At work, I’ve fallen in love with Git for our revision software. A co-worker told me that he uses Git to automatically backup his entire home directory on his computer, so I figured I could do something similar with the VPS that hosts this website.
There are two things required to make this work: Git, and a destination server to push your backup to.
The script I’m using is copied below (password redacted for security).
#!/bin/bash MYSQLUSER="root" MYSQLPASS="MyF4k3p4sSw0rd" DATE=$(date +%Y-%m-%d) pushd ~/backup mysqldump -u $MYSQLUSER -p$MYSQLPASS --all-databases > mysql/alldb.sql cp -r /var/www/* www/ git add . git commit -s -m "$DATE" git push origin master popd
All in all, pretty basic as far as things go. Dump the entire MySQL/MariaDB database, copy all the bare files from the /var/www directory, and then commit them to git. The other advantage of this is that it’s dead simple to restore a backup from any previous date. The nice advantage of using git is that it’s entirely OS agnostic, so I can restore the contents from one system to the other with minimal difficulties.