Skip to content

Instantly share code, notes, and snippets.

@Xeckt
Created June 10, 2021 09:35
Show Gist options
  • Save Xeckt/c2a4d1cba926eff07bb9764d4c0a9cc0 to your computer and use it in GitHub Desktop.
Save Xeckt/c2a4d1cba926eff07bb9764d4c0a9cc0 to your computer and use it in GitHub Desktop.
Rsync backup with remote destination file creation
#!/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
@Xeckt
Copy link
Author

Xeckt commented Jun 10, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment