My blog is backed up on GitHub and on Dropbox. This site is hosted on Oracle Cloud free tier. Discourse creates daily backups, but that won’t do me much good if something goes terribly wrong with Oracle Cloud. So I set up a process to sync those backups with my local machine.
The workhorse for this sort of task is
rsync. It only copies files when they don’t already exist on the destination machine and only the bits of files that have changed. You can also configure it to mirror a remote directory, meaning it will delete files when they are deleted on the remote system. The command I use is:
rsync -az --delete \ email@example.com:/var/discourse/shared/standalone/backups/default/ \ $HOME/Dropbox/meta_backups
Note that I’m putting the local copy in my Dropbox folder which means it’s also backed up on Dropbox.
Of course, that doesn’t much help if I forget to copy the backups regularly. I’d rather not lose months or even years of content. Fortunately macOS is Unix under the slick shell, so I can set up a cron job.
The crontab is fairly simple, with the addition of a few special strings:
I put a few things in
cron.sh that I’d like to run regularly:
#!/usr/bin/env zsh export PATH=/usr/local/bin:/usr/bin:/bin # https://medium.com/@jsstrn/scheduling-with-cron-c5e5191663c6 brew update -q brew upgrade brew cleanup -s #brew cask cleanup rsync -az --delete \ firstname.lastname@example.org:/var/discourse/shared/standalone/backups/default/ \ $HOME/Dropbox/meta_backups
While I was at it, I figured I’d also update my homebrew packages overnight. I might add other tasks as I go.
A quick check shows these backup files are coming in:
$ ls -l ~/Dropbox/meta_backups total 241408 -rw-r--r--@ 1 jericson _appstore 24467150 Jan 23 19:32 meta-jon-2023-01-24-033158-v20230103004613.tar.gz -rw-r--r--@ 1 jericson _appstore 24493213 Jan 23 22:02 meta-jon-2023-01-24-060045-v20230103004613.tar.gz -rw-r--r--@ 1 jericson _appstore 24681722 Jan 24 19:39 meta-jon-2023-01-25-033911-v20230103004613.tar.gz -rw-r--r--@ 1 jericson _appstore 24879809 Jan 25 19:33 meta-jon-2023-01-26-033319-v20230103004613.tar.gz -rw-r--r--@ 1 jericson _appstore 25071173 Jan 26 19:30 meta-jon-2023-01-27-033014-v20230103004613.tar.gz
Next step will be to verify that I can recover this site from a backup on another machine. But that’s a task for the future.