Automated, rotating server backup to Strongspace
/LICENSE /README.md /backup.sh /config /exclude-rsync.txt /exclude-tar.txt
Set up password-less logins to Strongspace.
To use multiple keys, name the file in which to save the key (e.g.
strongspace_rsa) and subsequently specify it as the identity file in
config. For example enter the code below to generate a new SSH key named
strongspace_rsa. After generating the keys it will prompt for a passphrase which will be used when accessing the key. Leave it blank when using it for scheduled rsync backup.
% ssh-keygen -f ~/.ssh/strongspace_rsa -t rsa
Set the permissions of the key pair, especially of the non-public key, to
% chmod 600 ~/.ssh/strongspace_rsa ~/.ssh/strongspace_rsa.pub
Add the public key
strongspace_rsa.pubto the authorized keys at Strongspace. Therefore, log into Strongspace, go to “Account” – “SSH Public Keys” – “Add a new key…” and paste the public key in there, finally save.
Create an SSH alias as done in
configand described in type less with a SSH alias. To test the setup, log into Strongspace using the command line
sftptool. While connecting to Strongspace it may prompt for continuation once, continue with
yes. After a successfull login, the command
% sftp ss
Create the directory where to store database dumps and the backup script on your server, set its permissons to
% mkdir -m 700 ~/backup
exclude-rsync.txt. Instructions on configuration are found inside
backup.sh. Upload the files to the before created directory
~/backupon your server. Set the permissons of
700and the other two to
To prevent possible errors when not running as root (e.g. group/owner bubkis on a TextDrive Shared), add the line
The rest should be left as is.
Create the directories that will be used for the backup rotation purpose on Strongspace; they must all be in that same Strongspace Space.
Test the script and check that it runs okay.
--verbose) to display the messages instead of writing them to the log file
~/backup/backup.log. Besides, verbose mode also turns off email notification.
--localonly) the backup is stored only locally without any synchronization with Strongspace.
--resetlog) empties the log file before writing to it and
--deleteunlisted) deletes backups of unlisted databases, directories and files; i.e.
% ~/backup/backup.sh -vlLU
or in a more readable form
% ~/backup/backup.sh --verbose --localonly --resetlog --deleteunlisted
Finally add it as a cronjob.
On a Joyent SmartMachine Standard use
ewhile logged in as root to schedule a backup.
% crontab -e
For a backup once a week, for example at 6:00 a.m. every monday, add in a new line:
0 6 * * 1 /full-pathname-to/backup/backup.sh
Save, quit and it should run automatically on the next scheduled date.
On a Joyent SmartMachine Plus log into Webmin and navigate to “Webmin” – “System” – “Scheduled Cron Jobs”. There hit “Create a new scheduled cron job”. In the input box labelled “Execute cron job as” put
rootand in the input box labelled “Command” put the path to your backup script (dependent on its location, e.g.
/root/backup/backup.sh). Finally set the day and time when you want it to execute and hit “Create” to finish.
On a TextDrive Shared log into Virtualmin and navigate to “Webmin Modules” – “Scheduled Cron Jobs”. There hit “Create a new scheduled cron job”. In the input box labelled “Command” put the path to your backup script (e.g.
/users/home/USERNAME/backup/backup.sh). Finally set the day and time when you want it to execute and hit “Create” to finish.
LICENSE for license and copyright details.
Kudos to ExpanDrive (Password-less login to Strongspace with SSH Keys, Type less with a SSH Alias, Automated Offsite MySQL backup to Strongspace), Joyent and TextDrive.