Backups

So, it’s been another year and I’m getting better settled in to Linux. I’ve run through a lot of different window managers and desktop environments, like KDE, i3 and WindowMaker, before settling on DWM. Add to that more than a fair share of auxiliary programs to flesh out the experience and make things customized for me.

To that end, I’ve been trying to ensure that if anything should fail, I have a good backup to restore from. Enter Borg. It’s a command-line driven backup tool that not only compresses and encrypts the contents, but it de-duplicates it. This is fantastic for lots of little text files and the occasional photo set. The problem for me was, it was a lot of hassle feeding it all the options needed every time. Sure, I could alias it to make it simpler, but that still left a bit of work for me to do to get everything sorted, including un/mount the backup share, putting in a myriad of passwords, checking for number of incremental backups and pruning them so that I’m not dropping hundreds of gigabytes of useless, mostly similar backups (dedup’d or not) on my server, and on my offsite storage.

So, like most things on Linux, I glued all this together in a simple Fish Shell function. This allows me to just run a command (or add it as a user systemd timer) that backs everything I care about up, prunes and does all the drudgery of making a nice secure backup. Here’s my script/function that makes this all easier.

function my-backup -d "Mounts backup and runs borg"

	# Check for borg, first, bail out if it's not found
	if [ ! -x /usr/bin/borg ]
	    echo "Borg not found, please install before running this script."
	    exit 1
	end

	# Check to see if the repo pass is available. We use this to avoid
	# typing passwords all the time
	set -x BORG_PASSCOMMAND ""
	set -x CURRENT_DIR (pwd)

	# What to back up
	# Home Dir Top Level
	set -x BACKUP_FILES Documents Pictures .config .local .gnupg .xsession
	# Home misc
	set -a BACKUP_FILES /home/ndegruchy/.local/share/Steam/userdata/9974372/
	# Etc
	set -a BACKUP_FILES /etc/pacman.conf /etc/makepkg.conf
	# Emacs
	set -a BACKUP_FILES /usr/share/emacs/site-lisp/default.el
	# Package lists
	set -a BACKUP_FILES $MY_AUR_LIST $OFFICIAL_PACKAGE_LIST

	# Pacman package list backups, these are mine, the system will
	# (eventually) generate a full list at /etc/pkglist.txt
	echo "Exporting Pacman package lists"
	pacman -Qqem > $MY_AUR_LIST

	# Go home, for context
	cd ~

	# Check to see if the backup share is mounted, if not mount it
	if [ ! -d /mnt/backups/degruchy ]
	    echo "Mounting backup share to /mnt/backups/"
	    echo "You will need your password to do this."
	    sudo mount ...
	end

	echo "Trying to create a backup in /mnt/backups/degruchy with today's date and hostname."

	borg create --stats --progress --comment "New automated backup of critical stuff" --compression auto,lzma,6 /mnt/backups/degruchy::(date +%F)-(hostname) $BACKUP_FILES --exclude-from ~/.config/borg/exclude-file

	set -x IS_PHONE_PLUGGED (lsusb | grep -i "Apple" | wc -l)

	if [ $IS_PHONE_PLUGGED -gt 0 ]
	    ## TODO: The phone data is copied locally, first, probably a
	    ## good idea to check for available space, first.
	    echo "Looks like your phone is plugged in, backing that up, too..."
	    set -x PHONETEMP $HOME/.cache/temp/(date +%F)-nathans_phone
	    mkdir $PHONETEMP
	    idevicebackup2 backup $PHONETEMP
	    borg create --stats --progress --comment "Nathan's Phone backup" --compression auto,lzma,6 /mnt/backups/iPhoneBackups/::(date +%F)-nathans_phone $PHONETEMP
	    rm -rf $PHONETEMP
	end
	
	echo "Checking for backup prunability..."
	
	# Clean up old backups
	echo "Pruning..."
	borg prune --list --keep-daily 7 --keep-weekly 4 --keep-monthly 6 /mnt/backups/degruchy/
	borg prune --list --keep-daily 7 --keep-weekly 4 --keep-monthly 6 /mnt/backups/iPhoneBackups/

	echo "Unmounting backup. You may need your password again."
	sudo umount /mnt/backups
	echo "All done!"

		# Go back to where you were, if not already there
	if [ -d $CURRENT_DIR ]
	    cd $CURRENT_DIR
	else
	    cd ~
	end

	# Dump all the variables
	set -e CURRENT_DIR
	set -e BORG_PASSCOMMAND
	set -e BACKUP_FILES
	set -e IS_PHONE_PLUGGED
	set -e PHONETEMP
end

How to Make an Emergency Stove

So awesome!

Incredible ingenuity. Basically allows you to build a lightweight stove for next to nothing, available just about anywhere on the planet and one that you won’t cry over loosing, damaging or otherwise not having anymore.

I love these kinds of “life hacks”. Which is why I was so happy to find a whole subreddit of these things. I especially like travel ones, because travel is always such a pain when you want to carry what you need through airports and FSM-knows what else.

I think it might be time to build my own little group of life tips.

Nathan’s Computing Tips

  • Don’t like having to remember complicated passwords? Try making silly sentences related the login you are creating. E.g.: “Google me up a kipper!“. The punctuation helps keep the password complex, but is also easier for you to remember. You can also “mix” several words together to create one long string of gibberish that you can remember with just a mention of some random words.
    • Barring that, get a password manager. There are plenty to choose from. Ranging from the free and open source KeePass to the closed source, but very good 1Password. The big advantage to this is that you can let the system generate a strong password for you.
  • Want to let your friend use your computer? Look for a guest account feature. Windows and Mac have this feature built in, but disabled. Linux users… well, you know what to do.
  • Want to save power on your cellphone at work? Turn on Airplane mode, then re-enable wireless (if you have wireless). Just tell your friends to call you at work if they need to.
  • Rip DVDs to your computer for long trips. Saves power and reduces crap you have to carry.
  • Back up your data. No. Seriously, if you read this list and only learn one tip, learn this one. Even if you just go out and buy a cheap external drive. Do it. This is especially handy if you need to get out of your house during an emergency and can’t take your desktop/laptop/whatever. Grab the drive and go.
  • Need to use a scummy computer in a scummy place that you don’t trust? Download Tails (or any other Live Linux USB OS) to ensure that your communication online is from a trusted source. Though you can’t rule out hardware keyloggers.