My attempt was to create a simple and secure remote backup script. Right now it only works with MySql (or MariaDB).
- 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.
Version: 0.1 Release Notes
- Backup checksum storage (database, flatfile?)
- Email Notification
- Push notification via SMS for errors via Twillio
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)
- Linux or OS X
- GNU bash > 3.5
- Rsync on both servers
- mysqldump commandline tool
It assumes you are using public/private keys for authentication via SSH.
It assumes you have user-specific mysql configuration. Such as the following
[mysqldump] host=localhost user=youruser password=password123
The default port is 22 if not specified
Backup.sh -c email@example.com -p 2121 -r /path/to/backup -m -b dbname
This can be ran via cron jobs.
To see a list of options.