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://techoverflow.net/2020/12/10/how-to-create-a-systemd-backup-timer-service-in-10-seconds/
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]
[email protected]%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
[email protected]%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