I was put off by Tarsnap Backup when I ran into it many years ago. I liked that it’s trusted and secure enough to be used by companies like Stripe, but I just didn’t want to put in the work to modify configuration files, write shell scripts, and set up cron jobs to backup my files. That felt like too much effort for me to manage. I have a laptop, not a server.
But over time, my backups have become a bit of a fragmented mess. I ended up adopting multiple services (and overpaying for storage) because they were easy and tightly integrated with my devices. I have iCloud for my photos, OneDrive for my documents, and Backblaze for everything else on my computer.
I wanted to consolidate everything I had into a single place, and I wanted it to be cheap and secure. Tarsnap came to mind again because it’s inexpensive enough for my needs, and I like that I’d be the only one holding the encryption keys. (It costs $0.25 per GB, so it’s not the cheapest one out there, but deduplication has done wonders for me.)
This is how I have it set up on Windows through WSL.
I don’t want it to make a backup of my whole drive because that will take forever to upload on my 5Mbps network. Even though Tarsnap is affordable, it could get expensive if I backup unnecessary program files.
So in this script, I created a variable called
$directories in the backup script that lists out the folders I care about in both Windows and Linux.
#!/usr/bin/fish set directories "/mnt/c/Users/jag/Documents" "/mnt/c/Users/jag/Desktop" "/home/jag" /usr/bin/tarsnap -v -c -f (uname -n)"-"(date +%Y-%m-%d_%H-%M-%S) \ $directories
I want the backup to run automatically in the background, so I had to set a cronjob. I typed in
crontab -e and set Tarsnap to run every half hour (4pm, 4:30pm, 5pm, etc.)
*/30 * * * * /home/jag/tarsnap-backup.sh
I haven’t run into this, but I’ve read that cron can fail silently. So I had Dead Man’s Snitch set up as well to warn me if my cronjob didn’t run in the last 24hrs just to be extra safe. They have a program called a Field Agent that monitors execution time and output of the backup script.
*/30 * * * * /home/jag/dms -s 012345 /home/jag/tarsnap-backup.sh
Cron in the background
This part gets pretty hacky. The problem is that the cron service doesn’t start automatically in WSL 2. Even though I have cron configured, it’s not going to execute unless the cron service runs in the background. Not having a normal boot process means that services in Linux have to be started manually, but I didn’t want to run the backup myself every time I boot up! I’d have to run the following manually:
- Open Windows Terminal
- Start Windows Subsystem for Linux by typing
sudo /etc/init.d/cron start
- Type in my password
I needed to make all these steps automatic. First, I removed the need to put it in a password when running cron by adding this to the sudoers file (which you can get to by typing in
jag ALL=ALL NOPASSWD:/etc/init.d/cron start, /etc/init.d/cron status
Now that I can start cron without a password, I can get it to run in the background without a password prompt when I log in to WSL. I added this condition to
.bashrc on Fish Shell):
# Start cron if it's not running. if sudo /etc/init.d/cron status | grep 'is not running' sudo /etc/init.d/cron start end
Now that I’m able to start cron automatically, all I needed to do is to run WSL when I log in on Windows. Pressing Win+R and typing in
shell:startup took me to the startup folder. In it, I wrote wsl.bat that just had
ubuntu.exe in it.
Easier Tarsnap commands
I have trouble remembering Tarsnap commands, so I made some aliases to make it simpler for me. I wrote this function in
function tarsnap switch $argv case stats command tarsnap --print-stats --humanize case archives command tarsnap --list-archives | sort | tail case extract command tarsnap -xf $argv[2..-1] case ls command tarsnap -tf $argv[2..-1] case '*' command tarsnap $argv end end
This means that I could just type in
tarsnap stats instead of
tarsnap --print-stats --humanize and
tarsnap archives instead of
tarsnap --list-archives | sort | tail. Much easier to work with!
Was it worth it?
That was quite a bit of work to figure out and set up—especially on Windows! There should be fewer (and less hacky) steps on macOS or Linux, but I’m glad that it’s all running smoothly for me. There’s nothing else for me to do aside from making sure that it’s running. It should also be easier to set up in a new machine now that I know how to get it to work.
So was it worth it? I think it is. The reason I did this in the first place was that Tarsnap was affordable and more secure than anything I’ve used before, so I think I still come out ahead even after all that work. We’ll see if I change backup preferences in the future, but for now I think I’m content with what I have.