Skip to content

Instantly share code, notes, and snippets.

@per2jensen
Created February 19, 2023 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save per2jensen/80c072f33cb2c2b7495c48e770a768a2 to your computer and use it in GitHub Desktop.
Save per2jensen/80c072f33cb2c2b7495c48e770a768a2 to your computer and use it in GitHub Desktop.
How I backup my darktable config directory on every login

Introduction

I use darktable (DT) as my RAW processing tool, and have so for many years now.

Losing my DT configurations and the database with tags and image metadata is something I don't want to experience.

For that reason I take backups in a couple of ways:

  • I do regular backups with my 'dar' scripts

  • In addition to that, when I login on my Ubuntu 22.04 desktop computer, a backup of ~/.config/darktable is made and stored on a cloud service.

The bash script taking a backup, first deletes backups older than 10 days and then does a 'dar' backup of the directory

Systemd user service

Location of the systemd user service ls: $HOME/.config/systemd/user/darktable-backup.service

I use this service description:

[Unit]
Description=Take backup of darktable config dir

[Service]
Type=oneshot
ExecStartPre=/bin/sleep 180
ExecStart=$HOME/.config/systemd/user/darktable-backup.sh
Restart=no

[Install]
WantedBy=default.target

The script starts approx 3 minutes after login. By that time the connection to my cloud provides should work just fine.

Bash script

Script location is: $HOME/.config/systemd/user/darktable-backup.sh

#! /bin/bash
CLOUDDIR=$HOME/<cloud-drive>/darktable-config


AGE_DATE=$(date --date="-10 days" -I)
AGE_SECS=$(date +%s --date "$AGE_DATE")
while IFS= read -r -d "" file
do
  FILE_DATE=$(echo $file|grep -o -E "darktable-config-[0-9]{4}-[0-9]{2}-[0-9]{2}")  # don't find dates in directory names
  FILE_DATE=$(echo $FILE_DATE|grep -o -E "[0-9]{4}-[0-9]{2}-[0-9]{2}")
  FILE_DATE_SECS=$(date +%s --date "$FILE_DATE")
  if (( AGE_SECS >= FILE_DATE_SECS )); then
      echo "cleanup: $file"
      rm -f "${file}"
  fi
done <   <(find "$CLOUDDIR" -type f -name "darktable-config-*.dar*" -print0)

# take a backup using "dar"
dar -c $CLOUDDIR/darktable-config-`date -I` -R "$HOME/" -g .config/darktable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment