My attempt was to create a simple and secure remote backup script. Right now it only works with MySql (or MariaDB).
Features
- Rsync+ssh+Gunzip
- Debugging options, readable terminal output/logging
This script will halt and exit immediately after any failed commands.
There are a lot of bad coding practices found with many bash scripts on the internet. There is a short list of good coding practices at the blog of Kevin van Zonneveld. Bash3boilerplate is a fantastic starter bootstrap for bash scripts with ideal code for any bash script. This backup script utilizes this template.
Download
Version: 0.1 Release Notes
ToDo:
- Backup checksum storage (database, flatfile?)
- Email Notification
- Push notification via SMS for errors via Twillio
Security
I avoid hardcoding login/auth credentials. Not only does this keep you from accidentally making a commit with your credentials, it keeps the script portable.
This script only works with private/public key pairs, and it only connects to servers whose fingerprints are known (typically these are hosts in ~/.ssh/known_hosts)
Requirements:
- Linux or OS X
- GNU bash > 3.5
- Rsync on both servers
- mysqldump commandline tool
- Gunzip
Important Notes
It assumes you are using public/private keys for authentication via SSH.
It assumes you have user-specific mysql configuration. Such as the following ~/.my.cnf
file.
[mysqldump]
host=localhost
user=youruser
password=password123
Example command:
The default port is 22 if not specified
Backup.sh -c user@backup.example.com -p 2121 -r /path/to/backup -m -b dbname
This can be ran via cron jobs.
Execute:
Backup.sh help
To see a list of options.