It was meant as a template, please modify it for your own use 
The first one is to check if device is not on metered network and has AC power, there are systemd native ways to check if the device is on AC power, perhaps you want to use that.
# /usr/local/bin/check-device
#!/usr/bin/env python3
########################################################
# Script to check the device stats to see if
# we can proceed with offsite backup and udpate
########################################################
import sys
import json
import subprocess
# Function to get output of shell command
def shell_exec(command):
res = subprocess.run(command, shell=True, capture_output=True, encoding="utf8", errors="replace")
output = res.stdout + res.stderr
return output.strip()
# Check if device is using metered network connection
command = "busctl --json=short get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered"
res = shell_exec(command)
res = json.loads(res)
if res.get("data") in [1, 3]:
print("Check failed. Currently using metered network connection.")
sys.exit(1)
# Check if device is on battery power
command = "busctl --json=short get-property org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower OnBattery"
res = shell_exec(command)
res = json.loads(res)
if res.get("data") is True:
print("Check failed. Currently using battery power.")
sys.exit(2)
# If we're here, it means none of the checks failed
print("Checks passed. Proceeding...")
sys.exit()
borgmatic is only necessary if you plan on performing a backup prior to daily dup, highly recommended!
Packages to install: borgbackup borgmatic
Here’s my borgmatic config for backing up to a remote server using ssh:
# /etc/borgmatic/config.yaml
source_directories:
- /rootfs.latest
- /home.latest
- /opt.latest
- /root.latest
- /srv.latest
- /usr-local.latest
- /var.latest
repositories:
- ssh://borg@ml1.mymailcheap.com/./suse-pc
encryption_passphrase: "<your-borg-repo-password>"
retention:
keep_daily: 7
keep_weekly: 4
hooks:
before_backup:
- btrfs subvolume snapshot -r / /rootfs.latest
- btrfs subvolume snapshot -r /home /home.latest
- btrfs subvolume snapshot -r /opt /opt.latest
- btrfs subvolume snapshot -r /root /root.latest
- btrfs subvolume snapshot -r /srv /srv.latest
- btrfs subvolume snapshot -r /usr/local /usr-local.latest
- btrfs subvolume snapshot -r /var /var.latest
after_backup:
- btrfs subvolume delete /rootfs.latest
- btrfs subvolume delete /home.latest
- btrfs subvolume delete /opt.latest
- btrfs subvolume delete /root.latest
- btrfs subvolume delete /srv.latest
- btrfs subvolume delete /usr-local.latest
- btrfs subvolume delete /var.latest
on_error:
- btrfs subvolume delete /rootfs.latest
- btrfs subvolume delete /home.latest
- btrfs subvolume delete /opt.latest
- btrfs subvolume delete /root.latest
- btrfs subvolume delete /srv.latest
- btrfs subvolume delete /usr-local.latest
- btrfs subvolume delete /var.latest
Validate borgmatic config file:
borgmatic config validate
Initialize borg repo:
borgmatic rcreate -e repokey
Perform a backup (this may take a while as it’s a first time sync):
borgmatic --verbosity 2
List all backups:
borgmatic list
Get information about backups:
borgmatic info
zypperoni is optional, it makes downloading packages faster. Not very important for non interactive dup.
atomic-update is an alternative to transactional-update for read-write root filesystems and recommended to prevent waking up to a broken/inconsistent system after the nightly non-interactive dup. I will try to write up a more detailed guide on this sort of setup when I have some time and try to submit atomic-update to OBS. For now, you would have to grab it from Github and not implicitly trust me or the code, it’s just 500 SLOC so give it a read 