Translation(s): English - Español - Français - српски

(!) ?Discussion

Backup and snapshot automation

Here is how to automate backup and snapshot tasks integrated into the modern Desktop environment.

Here, automation setup which doesn't rely on any specialized daemon nor cron but uses systemd service is presented.

You can use any combination of rsync, btrfs, and gpg commands, or any established command offered by programs listed in BackupAndRecovery.

See Backup for other proposals for automated Backups.

The following tips are generalized examples of initial author's experimental setup described in Btrfs Subvolume Snapshot Utility: bss.

Timer event based backup and snapshot

Let's say you have script which you want to execute automatically 30 seconds after starting your desktop environment and repeat it execution with 15 min (=900 sec.) intervals.

This can be enabled using systemd.

Create ~/.config/systemd/back-snap-timer.timer:

   1 [Unit]
   2 Description=Run on timer
   3 -h
   5 [Timer]
   6 OnStartupSec=30
   7 OnUnitInactiveSec=900
   9 [Install]

Create ~/.config/systemd/user/bkup-snap-BKUP.service as:

   1 [Unit]
   2 Description=Run command
   3 -h
   5 [Service]
   6 Type=oneshot
   7 Nice=15
   9 IOSchedulingClass=idle
  10 CPUSchedulingPolicy=idle
  11 StandardInput=null
  12 # No logging (use systemd logging)
  13 StandardOutput=null
  14 StandardError=null
  15 #StandardOutput=append:%h/.cache/systemd-bss.log
  16 #StandardError=append:%h/.cache/systemd-bss.log

Activate above from shell prompt with:

   1  $ systemctl --user enable bkup-snap-timer.timer

Mount event based backup and snapshot

Let's assume:

You can find out the systemd unit for mounting "BKUP" as

   1  $ systemctl list-units -t mount | fgrep -e '/media/username/BKUP'
   2   media-username-BKUP.mount    loaded active mounted /media/username/BKUP

Create ~/.config/systemd/back-snap-BKUP.service:

   1 [Unit]
   2 Description=USB Disk backup
   3 Requires=media-username-BKUP.mount
   4 After=media-username-BKUP.mount
   6 [Service]
   9 [Install]
  10 WantedBy=media-username-BKUP.mount

Activate above from shell prompt with:

 $ systemctl --user enable bkup-snap-BKUP.service

Desktop notification

When you write script for the above example, you can make it send messages to Desktop using notify-send command.

Here is an example of such script content to backup from ~/Documents to USB storage with Desktop notification.

   1 #!/bin/sh
   2 MSGID=$(notify-send -p "rsync: BACKUP" "backup in progress ...")
   3 # Backup from /home/penguin/Documents/ to USB storage mounted at /media/penguin/BACKUP
   4 rsync -aHxS --delete --mkpath /home/penguin/Documents/ /media/penguin/BACKUP/Documents
   5 notify-send -r "$MSGID" "rsync: BACKUP" "backup finished!"

The rsync is used here as an example only. This page will not elaborate backup program itself any further.

APT event based backup and snapshot

Let's assume you wish to run (before) and (after) on each apt upgrade event.

Create /etc/apt/apt.conf.d/80bkup-snap as:

   1   DPkg::Pre-Invoke  { "/usr/local/bin/" ; } ;
   2   DPkg::Post-Invoke { "/usr/local/bin/" ; } ;

GUI click event based backup and snapshot

Let's assume you wish to run on each GUI click to make network based remote backup.

Create ~/.local/share/applications/bkup-snap-GUI.desktop as:

   1 [Desktop Entry]
   2 Name=remote backup
   3 Comment=run rsync to
   5 Type=Application