Skip to content

Instantly share code, notes, and snippets.

@runjak
Last active October 21, 2017 18:31
Show Gist options
  • Save runjak/82c39d845a6c12fe9500 to your computer and use it in GitHub Desktop.
Save runjak/82c39d845a6c12fe9500 to your computer and use it in GitHub Desktop.
A short backup script using Borg
#!/bin/bash
# Inspired by https://borgbackup.readthedocs.org/en/stable/quickstart.html
# https://gist.github.com/ericmieth/c045edebb0709dfd88e1
# Created by mushu 2016-02-22
# Mounting the volume:
cryptsetup --key-file <keyFile> luksOpen UUID=<deviceUUID> cryptBackup
mount /dev/mapper/cryptBackup /mnt
# Verifying current backups:
borg check /mnt/backups
# Umounting the volume:
sync && umount /mnt
cryptsetup luksClose /dev/mapper/cryptBackup
# Scrub local btrfs:
btrfs scrub start / -B
# Going to sleep:
systemctl suspend
#!/bin/bash
# Inspired by https://borgbackup.readthedocs.org/en/stable/quickstart.html
# https://gist.github.com/ericmieth/c045edebb0709dfd88e1
# Created by mushu 2016-02-04
# Mounting the volume:
cryptsetup --key-file <keyfile> luksOpen UUID=<deviceUUID> cryptBackup
mount /dev/mapper/cryptBackup /mnt
# Performing the backup:
name=$(date -I)
sources='/etc /home /root'
target='/mnt/backups'
# Create a new backup:
borg create --exclude-caches $target::$name $sources
# Remove old backups:
borg prune -v $target --keep-daily=7 --keep-weekly=4 --keep-monthly=6
# Display current backups:
borg list $target
# Umounting the volume:
sync && umount /mnt
cryptsetup luksClose /dev/mapper/cryptBackup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment