Backup your latte configs with a service

I noticed a few more config wiping issues for latte dock, and I thought I’d share what I did to create backups since I’m a noob at making systemd services, and I figure this is where folks will search for a solution to that issue as well. No amount of someone simply saying “make a backup” is going to help me given how busy I am, so I took some initiative on behalf of other users to do this and document my process.

I wrote a script to backup to my smb share that I mounted in /etc/fstab bounced back and forth between these two tutorials to run that script on a schedule:

https://www.math.cmu.edu/~gautam/sj/blog/20200216-rsync-backups.html

I have a directory where i keep my scripts in my home directory, you probably keep them somewhere different, be mindful of that as you read through.

~/scripts/backup-latte-configs.sh :

#!/bin/bash

DATE=`date '+%Y%m%d-%H%M%S'`
LATTECONFIGDIR="/home/meredith/.config/latte"
ARCHIVETARGET="/mnt/fruitsalad/meredith/backups/latte/backup-latte-$DATE.tar.gz"

tar -cvzpf $ARCHIVETARGET $LATTECONFIGDIR

~/.config/systemd/user/backup.service :

[Unit]
OnFailure=notify-email@%i.service

[Service]
Type=oneshot
ExecStart=/bin/bash /home/meredith/scripts/backup-latte-configs.sh

~/.config/systemd/user/[email protected] :

[Unit]
Description=Send email

[Service]
Type=oneshot
ExecStart=sh -c 'systemctl --user status %i | \
mailx -s "[SYSTEMD %i] Fail" meredith'

~/.config/systemd/user/backup.timer :

[Unit]
Description="Automatically run backups"

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Then in konsole, test it and enable if it works:

systemctl --user start backup.service
systemctl --user enable backup.timer

if it doesn’t work, journalctl --user-unit=backup.service.

I hope this saves some users time and effort! Thank you for your help with this issue.

8 Likes

I appreciate the initiative and so I am commenting to support that friendly effort. I hope you find lots of support. Thank you again.

1 Like

You may configure the service to start after connecting to the network and mounting a fileshare if you wish. Find the name of the fileshare:

systemctl list-units --type=mount

and you should see something like mnt-foobar.mount. Add that to your service:

[Unit]
Description=Automatic backup service
After=network.target mnt-foobar.mount
OnFailure=notify-email@%i.service

For me, this was causing failures because it wasn't waiting for that mount. I had a VPN configured to autoconnect on login with another service, and it blocked my backup because it couldn't access my cifs volume. Now to hunt it down and make it load only after my backup service has run.

3 Likes

After I migrated to a new hard drive and decided it was pretty clunky to copy all my services and scripts over to the new machine, I decided just to create a repo with a backup service. Here it is for those interested. I’ve omitted the notify via email service because that takes some effort to set up, and I’m not about that when I can just periodically look at my backups directory to see what’s been backed up lately.

Open to feedback and pull requests.

3 Likes

No more latte, I see… :wink:
It was a tug at the heartstring to reread that name in the title…

Yeah, she was nice to us while she was around. :headstone:

This is a general backup script so maybe it deserves its own topic?

?

4 Likes