summaryrefslogtreecommitdiffstats
path: root/backup.sh
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-04-14 13:59:38 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-04-14 13:59:38 +0200
commit91ff2e96bb038be3b0cbf31cab28fbbb1452187e (patch)
treeb2c5027e8621db036a9165176007d64568fc852c /backup.sh
parentebf18b982b17ec7214bee7f02629e058f932c6b0 (diff)
downloadbin-91ff2e96bb038be3b0cbf31cab28fbbb1452187e.tar.gz
bin-91ff2e96bb038be3b0cbf31cab28fbbb1452187e.tar.xz
backup.sh: Misc changes; drop duplicity
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'backup.sh')
-rwxr-xr-xbackup.sh65
1 files changed, 13 insertions, 52 deletions
diff --git a/backup.sh b/backup.sh
index e191f3a..951a4e9 100755
--- a/backup.sh
+++ b/backup.sh
@@ -1,14 +1,15 @@
#!/bin/bash
#
-# This is a simple backup script using duplicity. It's supposed to serve as a
+# This is a simple backup script using borg. It's supposed to serve as a
# starting point and to be adjusted to your system.
#
# Important steps:
# - define a host "backup" in root's .ssh/config
# - read the script and adjust to your needs
-# - export BORG_REPO in your environment or create a wrapper in $PATH that
-# does it for calls to borg (my preference). For details on the variable
-# see man borg
+# - As root run `borg init -v --encryption=keyfile backup:borg-$HOSTNAME`
+# (note that zsh uses $HOST instead of $HOSTNAME)
+# - If you want, increase the max_segment_size in
+# ssh://backup/borg-$HOSTNAME/config from the default 5MiB
set -e
@@ -43,19 +44,8 @@ main() {
/mnt/data
)
- # first line that matches wins
- IFS='' read -r -d '' excludeList <<EOF || true
-+ /home/flo/.local/share/Steam/steamapps/common/Counter-Strike Global Offensive/csgo/cfg
-- /home/*/.local/share/Steam/steamapps/common/*/*
-- /home/*/.cache/*
-- /home/*/.claws-mail/imapcache
-- /root/.cache/*
-- /var/cache/pacman/pkg/*
-EOF
-
- # same as above, but for borg backup. Note that borg uses a different
- # syntax and does not support including lower level directories
- # (TODO: verify this claim)
+ # list of patterns that should be excluded. This supports shell globbing as
+ # well as regex pattern. Refer to man borg for details.
IFS='' read -r -d '' excludeList_borg <<EOF || true
sh:/home/flo/tmp/*
sh:/home/*/.cache/*
@@ -64,7 +54,6 @@ sh:/var/cache/pacman/pkg/*
EOF
exclude_mountpoints
- echo "$excludeList" > "$TMPDIR/exclude-list"
echo "$excludeList_borg" > "$TMPDIR/exclude-list-borg"
# save some data that's useful for restores
@@ -78,43 +67,15 @@ EOF
df -a > "$backupDataDir/df"
findmnt -l > "$backupDataDir/findmnt"
- backup_borg /
-
- #local backupdir="$HOSTNAME-backup/full-backup"
- #backup_duplicity / "sftp://backup/$backupdir/" --exclude-filelist "$TMPDIR/exclude-list"
- #ssh backup "touch $backupdir/last-backup-timestamp"
-}
-
-backup_duplicity() {
- local src=$1
- local dest=$2
- shift 2
- local -a options=()
-
- if [[ $(date +%d ) == '1' ]]; then
- # try to only run full backups on day 1 each month
- options+=(--full-if-older-than 2D)
- else
- # force a full backup once in a while
- options+=(--full-if-older-than 30D)
- fi
+ # TODO: create snapshots here if possible. Sadly that's really difficult so
+ # it will probably not be implemented
- #export PASSPHRASE
- HOME=/root duplicity \
- -v5 \
- --numeric-owner \
- --volsize 250 \
- --allow-source-mismatch \
- --asynchronous-upload \
- --no-encryption \
- "${options[@]}" "$@" "$src" "$dest"
-
- HOME=/root duplicity --force remove-older-than 120D "$dest"
- #export PASSPHRASE=""
+ backup_borg / "backup:borg-$HOSTNAME"
}
backup_borg() {
local src=$1
+ local dst=$2
borg create \
-v \
@@ -123,9 +84,9 @@ backup_borg() {
--stats \
--progress \
--exclude-from "$TMPDIR/exclude-list-borg" \
- "::backup-$(date "+%Y%m%d-%H%M%S")" "$src"
+ "$dst::backup-$(date "+%Y%m%d-%H%M%S")" "$src"
- borg prune -v --keep-within 3m
+ borg prune -v --keep-within 6m "$dst"
}
### support functions below ###