Skip to content

Commit

Permalink
Merge pull request #15 from ikifar2012/2021.5.0
Browse files Browse the repository at this point in the history
2021.5.0
  • Loading branch information
ikifar2012 authored May 14, 2021
2 parents 9103d26 + 9b9c8f2 commit 132f915
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 12 deletions.
6 changes: 6 additions & 0 deletions remote-backup/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2021.5.0

- Added rclone
- Upgraded Base to 9.2.0
- rsync now excludes all database files

# 2021.4.1

- Removed extra `:` in $rsyncurl
Expand Down
30 changes: 28 additions & 2 deletions remote-backup/DOCS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Configuration

Below is an example configuration:

```yaml
ssh_enabled: true
friendly_name: true
Expand All @@ -17,7 +19,9 @@ rsync_rootfolder: hassio-sync
rsync_user: ''
rsync_password: ''
```
# Options
## Options
|Parameter|Required|Description|
|---------|--------|-----------|
|`ssh_enabled`|No|Allows you to disable or enable the SSH function|
Expand All @@ -29,4 +33,26 @@ rsync_password: ''
|`ssh_key`|Yes|The filename of the SSH key, this must be located in the `ssl` directory of Home Assistant which can be accessed through SAMBA under the share name `ssl`|
|`remote_directory`|Yes|The destination directory where the snapshots will be placed|
|`zip_password`|No|If set then the backup will be contained in a password protected zip file|
|`keep_local_backup`|No|Control how many local backups you want to preserve on the Home Assistant host. The default (`""`) is to keep no local backups created from this addon. To keep all backups set this to `all` then all local backups will be preserved. This can also be set with a number to preserve only the specified amount|
|`keep_local_backup`|No|Control how many local backups you want to preserve on the Home Assistant host. The default (`""`) is to keep no local backups created from this addon. To keep all backups set this to `all` then all local backups will be preserved. This can also be set with a number to preserve only the specified amount|

# Rclone (Experimental)

To use simply place your rclone.conf file in the `/ssl/` share, these can be generated using the `rclone config` command on any computer running rclone, example shown below:

```ini
[backblaze]
type = b2
account = xxxxxxxxxx
key = xxxxxxxxxxx
```

## Options

|Parameter|Required|Description|
|---------|--------|-----------|
|`rclone_enabled`|No|Allows you to disable or enable the rclone function|
|`rclone_copy`|No|Enables rclone copy mode|
|`rclone_sync`|No|Enables rclone sync mode|
|`rclone_restore`|No|Restores files in remote to a date stamped folder in `/backup/`|
|`rclone_remote`|Yes|The name of the remote specified in rsync.conf, example: `backblaze`|
|`rclone_remote_directory`|Yes|The path of the remote directory which the addon will save to, including bucket name if using a service like backblaze|
7 changes: 6 additions & 1 deletion remote-backup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV LANG C.UTF-8

# Setup base
RUN apk add --no-cache jq openssh-client zip sshpass rsync wget
RUN apk add --no-cache jq openssh-client zip sshpass rsync wget curl unzip

# Rclone CLI
ARG BUILD_ARCH
RUN curl https://rclone.org/install.sh | bash


# Hass.io CLI
ARG BUILD_ARCH
Expand Down
10 changes: 5 additions & 5 deletions remote-backup/build.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"squash": false,
"build_from": {
"aarch64": "ghcr.io/hassio-addons/base/aarch64:9.1.6",
"amd64": "ghcr.io/hassio-addons/base/amd64:9.1.6",
"armhf": "ghcr.io/hassio-addons/base/armhf:9.1.6",
"armv7": "ghcr.io/hassio-addons/base/armv7:9.1.6",
"i386": "ghcr.io/hassio-addons/base/i386:9.1.6"
"aarch64": "ghcr.io/hassio-addons/base/aarch64:9.2.0",
"amd64": "ghcr.io/hassio-addons/base/amd64:9.2.0",
"armhf": "ghcr.io/hassio-addons/base/armhf:9.2.0",
"armv7": "ghcr.io/hassio-addons/base/armv7:9.2.0",
"i386": "ghcr.io/hassio-addons/base/i386:9.2.0"
},
"args": {}
}
18 changes: 15 additions & 3 deletions remote-backup/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Remote Backup",
"version": "2021.4.1",
"version": "2021.5.0",
"slug": "remote_backup",
"description": "Automatically create and backup HA snapshots using SCP",
"url": "https://github.com/ikifar2012/remote-backup-addon/blob/master/README.md",
Expand Down Expand Up @@ -32,7 +32,13 @@
"rsync_host": "",
"rsync_rootfolder": "hassio-sync",
"rsync_user": "",
"rsync_password": ""
"rsync_password": "",
"rclone_enabled": false,
"rclone_copy": false,
"rclone_sync": false,
"rclone_restore": false,
"rclone_remote": "",
"rclone_remote_directory": ""
},
"schema": {
"ssh_enabled": "bool",
Expand All @@ -49,6 +55,12 @@
"rsync_host": "str",
"rsync_rootfolder": "str",
"rsync_user": "str",
"rsync_password": "str"
"rsync_password": "str",
"rclone_enabled": "bool",
"rclone_copy": "bool",
"rclone_sync": "bool",
"rclone_restore": "bool",
"rclone_remote": "str",
"rclone_remote_directory": "str"
}
}
49 changes: 48 additions & 1 deletion remote-backup/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ RSYNC_HOST=$(bashio::config "rsync_host")
RSYNC_ROOTFOLDER=$(bashio::config "rsync_rootfolder")
RSYNC_USER=$(bashio::config "rsync_user")
RSYNC_PASSWORD=$(bashio::config "rsync_password")
RCLONE_ENABLED=$(bashio::config "rclone_enabled")
RCLONE_COPY=$(bashio::config "rclone_copy")
RCLONE_SYNC=$(bashio::config "rclone_sync")
RCLONE_RESTORE=$(bashio::config "rclone_restore")
RCLONE_REMOTE=$(bashio::config "rclone_remote")
RCLONE_REMOTE_DIRECTORY=$(bashio::config "rclone_remote_directory")

# create variables
SSH_ID="/ssl/${SSH_KEY}"
Expand Down Expand Up @@ -81,7 +87,7 @@ function rsync_folders {
echo "[Info] trying to rsync ha folders to $rsyncurl"
echo ""
echo "[Info] /config"
sshpass -p $RSYNC_PASSWORD rsync -av --exclude '*.db-shm' --exclude '*.db-wal' /config/ $rsyncurl/config/ --delete
sshpass -p $RSYNC_PASSWORD rsync -av --exclude '*.db-shm' --exclude '*.db-wal' --exclude '*.db' /config/ $rsyncurl/config/ --delete
echo ""
echo "[Info] /addons"
sshpass -p $RSYNC_PASSWORD rsync -av /addons/ $rsyncurl/addons/ --delete
Expand All @@ -98,6 +104,46 @@ function rsync_folders {
fi
}

function rclone_snapshots {
if [ "$RCLONE_ENABLED" = true ] ; then
cd /backup/
mkdir -p ~/.config/rclone/
cp -a /ssl/rclone.conf ~/.config/rclone/rclone.conf
echo "Starting rclone"
if [ "$RCLONE_COPY" = true ] ; then
if [ "$FRIENDLY_NAME" = true ] ; then
if [[ -z $ZIP_PASSWORD ]]; then
echo "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${name}.tar"
rclone copyto ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".tar
else
echo "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${name}.zip"
rclone copyto ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}/"${name}".zip
fi
else
if [[ -z $ZIP_PASSWORD ]]; then
echo "Copying ${slug}.tar to ${RCLONE_REMOTE_DIRECTORY}/${slug}.tar"
rclone copy ${slug}.tar ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}
else
echo "Copying ${slug}.zip to ${RCLONE_REMOTE_DIRECTORY}/${slug}.zip"
rclone copy ${slug}.zip ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}
fi
fi
fi
if [ "$RCLONE_SYNC" = true ] ; then
echo "Syncing Backups"
rclone sync . ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY}
fi
if [ "$RCLONE_RESTORE" = true ] ; then
DATEFORMAT=$(date +%F)
RESTORENAME="restore-${DATEFORMAT}"
mkdir -p "${RESTORENAME}"
echo "Restoring Backups to ${RESTORENAME}"
rclone copyto ${RCLONE_REMOTE}:${RCLONE_REMOTE_DIRECTORY} ${RESTORENAME}/
fi
fi
}


function delete-local-backup {

ha snapshots reload
Expand Down Expand Up @@ -126,6 +172,7 @@ add-ssh-key
create-local-backup
copy-backup-to-remote
rsync_folders
rclone_snapshots
delete-local-backup

echo "Backup process done!"
Expand Down

0 comments on commit 132f915

Please sign in to comment.