Skip to content

Instantly share code, notes, and snippets.

@reo7sp
Last active August 20, 2016 22:00
Show Gist options
  • Save reo7sp/0253c1e0952df9fb0618c56bfd6d3d97 to your computer and use it in GitHub Desktop.
Save reo7sp/0253c1e0952df9fb0618c56bfd6d3d97 to your computer and use it in GitHub Desktop.
#!/bin/bash
sshport=22
sshcert=~/.ssh/id_rsa
remoteserver= # FILL IN, e.g [email protected]
localpath= # FILL IN without trailing slash, e.g ~/backups/server
usesudo= # FILL IN true or false
if [[ $usesudo == true ]]; then
rsyncargs=(-rlptzhu -e "ssh -p $sshport" --rsync-path="sudo rsync" --partial --delete-after --info=progress2)
else
rsyncargs=(-rlptzhu -e "ssh -p $sshport" --partial --delete-after --info=progress2)
fi
echo ":: Authenticating..."
ssh-add -l > /dev/null
if [[ $? != 0 ]]; then
ssh-add $sshcert
fi
backup() {
echo; echo ":: Backuping $1..."
mkdir -p $localpath/$1
rsync "${rsyncargs[@]}" $remoteserver:$1/ $localpath/$1
}
backup /etc
backup /home
backup /var/lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment