Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
- # Defining variables
- TIMESTAMP=$(date '+%Y%m%d%H%M%S')
- PID=$$
- STATUSFILE=/var/run/restic_backup_status
- STDERR=/var/log/restic_backup-error.log
- STDOUT=/var/log/restic_backup-status.log
- # What should be backed up
- if [ "$1" == "--wife" ]; then
- TAG=wife
- elif [ "$1" == "--full" ]; then
- TAG=full
- else
- TAG=kervyn
- fi
- # Checking if backup is already running
- if [ -f $STATUSFILE ]; then
- echo "Backup is already running"
- exit 99
- fi
- # Write Backupinformation
- cat << __EOF__ > $STATUSFILE
- $PID
- Started: $TIMESTAMP
- __EOF__
- # Creating snapshots and mount it
- lvcreate -L100G -s -n $TIMESTAMP-snap-lvsrv /dev/vg0/lvsrv >/dev/null
- mkdir -p /mnt/lv-snapshots/snap-lvsrv
- mount -o ro /dev/vg0/$TIMESTAMP-snap-lvsrv /mnt/lv-snapshots/snap-lvsrv
- lvcreate -L100G -s -n $TIMESTAMP-snap-lvtimemashine /dev/vg0/lvtimemashine >/dev/null
- mkdir -p /mnt/lv-snapshots/snap-lvtimemashine
- mount -o ro /dev/vg0/$TIMESTAMP-snap-lvtimemashine /mnt/lv-snapshots/snap-lvtimemashine
- # Backup
- /opt/restic --repo rclone:hetzner-storagebox-europa: \
- --tag ${TAG} --json --compression=max \
- --password-file=/etc/restic/resticpw backup \
- --files-from=/etc/restic/${TAG}.include \
- --exclude-file=/etc/restic/${TAG}.exclude > $STDOUT 2> $STDERR
- # Unmouning and removing snapshots
- umount /mnt/lv-snapshots/snap-lvsrv
- lvremove -f /dev/vg0/$TIMESTAMP-snap-lvsrv >/dev/null
- rmdir /mnt/lv-snapshots/snap-lvsrv
- umount /mnt/lv-snapshots/snap-lvtimemashine
- lvremove -f /dev/vg0/$TIMESTAMP-snap-lvtimemashine >/dev/null
- rmdir /mnt/lv-snapshots/snap-lvtimemashine
- # removing pid file
- rm $STATUSFILE
- # send statistics to zabbix
- grep -F '"message_type":"summary",' $STDOUT | /etc/restic/restic_stats_to_zabbix.rb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement