Created
June 10, 2021 09:35
-
-
Save Xeckt/c2a4d1cba926eff07bb9764d4c0a9cc0 to your computer and use it in GitHub Desktop.
Rsync backup with remote destination file creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_backup_serv="username@ip_address" | |
_backup_loc="/volume1/backups/example" | |
_current_date=$(date '+%Y-%m-%d-%H:%M:%S') | |
if [[ $1 == "--backup-sys" ]]; then | |
if [[ $2 == "--test" ]]; then | |
rsync -aXv --delete --dry-run --rsync-path="mkdir -p $_backup_loc/$_current_date && rsync" --exclude="/media" --exclude="/mnt" --exclude="/proc" --exclude="/sys" --exclude="/var/lock/" --exclude="/var/lock/" --exclude="/var/run/" / $_backup_serv:$_backup_loc/$_current_date | |
else | |
echo "Unable to perform dry-run of rsync?"; exit | |
fi | |
rsync -aXv --delete --rsync-path="mkdir -p $_backup_loc/$_current_date && rsync" --exclude="/media" --exclude="/mnt" --exclude="/proc" --exclude="/sys" --exclude="/var/lock/" --exclude="/var/lock/" --exclude="/var/run/" / $_backup_serv:$_backup_loc/$_current_date | |
else | |
echo "Unable to perform rsync backup."; exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple usage if you place in /usr/local/bin
ctl --backup-sys --test
to perform a dry-run of rsync.ctl --backup-sys
to perform the rsync backup.Don't forget to
chmod +x /usr/local/bin/ctl
or whatever filename you give it.