~/blog/"My (semi-)automated backup script"

2022-11-08


In the age of cloud file storage, people often put too much faith into companies like Google, Apple, and Dropbox to keep their important files safe. Even ignoring the possible privacy/security concerns, you’re still trusting them to not cut off your access for some reason beyond your control. Thus, you should seriously consider periodically backing up your important files to an external physical device.

I backup my files on a monthly basis, so having to Ctrl-c/Ctrl-v a bunch of times is not ideal. Fortunately, I can now avoid this with a simple script:

#!/bin/sh

if [ "$#" != 1 ]; then
    printf 'ERROR! No path to backup directory provided!\n' >&2
    exit 1
fi

DATE=$(date +'%Y-%m-%d')

cd "$HOME"
crontab -l > crontab.txt
zip -9 -r "$1$DATE.zip" ".ssh/" "crontab.txt"
rm crontab.txt

zip -9 -r "$1$DATE.zip" \
    "browsing/" \
    "code/" \
    "vimwiki/" \
    -x "code/**/target/*" \
    -x "code/**/.vscode/*" \
    -x "code/**/build/*" \
    -x "code/**/*.swp" \
    -x "*/.git/*"

The script compresses the files that I want recursively (-r) with the maximum compression setting (-9), and ignores some directories (-x) that contain version control information and binaries build from code I’ve worked on. This is then put in the directory passed to the script and named with the current date ($1$DATE.zip).

The backup directory is inside a pen-drive that’s been encrypted with LUKS.

Limitations

Although the script automates most of the process, there are still a few things that I have to do manually:

  1. I’ve got to plug-in the pen-drive and decrypt it.
  2. The browsing/ directory contains a copy of the RSS feeds that I follow (exported manually from Feedly), and the bookmarks manually exported from my browser (brave).

Point 1 does not bother me, but point 2 definitely makes me itch.

I might eventually move to a self-hosted solution for my RSS reader needs (maybe Tiny Tiny RSS). It’s more involved, so it makes sense that it requires extra work. However, not being able to export my bookmarks from brave using the command line is seriously frustrating.

From a bit of research, I’ve found that the bookmarks are stored in ~/.config/BraveSoftware/Brave-Browser/Default/Bookmarks, but they are not in the HTML format exported by brave. At some point, I might just write some hacky script to convert between the two.

If you happen to have a better solution, do please let me know. 🙂