Translation(s): English - Español - Français - српски
?Discussion
Contents
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 bkup-snap-timer.sh 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:
Create ~/.config/systemd/user/bkup-snap-BKUP.service as:
1 [Unit]
2 Description=Run bkup-snap-timer.sh command
3 Documentation=bkup-snap-timer.sh -h
4
5 [Service]
6 Type=oneshot
7 Nice=15
8 ExecStart=bkup-snap-timer.sh
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 have a USB storage media with usable formatted partition (Filesystem is labeled as "BKUP")
- Your user name is "username".
- Upon plugging in the USB storage, the Desktop system automatically mount it to "/media/username/BKUP".
You want to run bkup-snap-mount.sh script automatically upon mount event of USB storage device
You can find out the systemd unit for mounting "BKUP" as
Create ~/.config/systemd/back-snap-BKUP.service:
Activate above from shell prompt with:
$ systemctl --user enable bkup-snap-BKUP.service
Desktop notification
When you write bakup-snap-mount.sh 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 bkup-snap-pre.sh (before) and bkup-snap-post.sh (after) on each apt upgrade event.
Create /etc/apt/apt.conf.d/80bkup-snap as:
GUI click event based backup and snapshot
Let's assume you wish to run bkup-snap-GUI.sh on each GUI click to make network based remote backup.
Create ~/.local/share/applications/bkup-snap-GUI.desktop as: