I use the awesome tool borg for my backups. Although I really like most CLI tools, I always found the borg syntax quite hard to remember.
That's why I created this little bash-script that I use on all of my machines:
#!/usr/bin/env bash
# Borg repository
REPO="server@coruscant:/media/hdd-master/borg"
# Source files
FILES="/home/mrupp"
if [ $1 == "init" ]; then
borg init -e repokey $REPO
exit 0
fi
if [ $1 == "create" ]; then
borg create --progress "$REPO::$(date +"%y-%m-%d_%H-%M-%S")" $FILES
exit 0
fi
if [ $1 == "mount" ]; then
mkdir -p ~/_borg
borg mount $REPO ~/_borg
exit 0
fi
if [ $1 == "umount" ]; then
borg umount ~/_borg
rm -rf ~/_borg
exit 0
fi
if [ $1 == "list" ]; then
borg list $REPO
exit 0
fi
echo "Invalid command: $1"
exit 1
After configuring both variables and running ./borg.sh init
once, creating backups is as simple as typing ./borg.sh create
.
The mount
option is also quite useful as it allows to quickly restore files from the backup in case of an emergency.
For the version that I use on my cloud-servers, I added these two lines:
export BORG_RSH="sshpass -p <password> ssh -p 23 -l <username>"
export BORG_PASSPHRASE="<passphrase>"
This way, no password has to be entered manually and the backup can run fully automated e.g using cron:
$ sudo crontab -l
#Ansible: storagebox_backup
15 7,11,22 * * * /opt/borg.sh create
The risk of storing the password in plain text on the server, however, might be problematic for some use cases.