-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
55 lines (41 loc) · 1.58 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
set -e
# SFTP:
#REMOTE_USER="BACKUPUSER@BACKUPHOST"
#REPO_URL="sftp:$REMOTE_USER:backups/"
# S3:
# export AWS_ACCESS_KEY_ID="bucket-access-key"
# export AWS_SECRET_ACCESS_KEY="bucket-secret"
# REPO_URL="s3:sos-ch-gva-2.exo.io/bucket-name"
CANARY_HASH='abcdef-02134-abcdef-02134'
LOGFILE="/var/log/restic/`date +"%Y%m%d-%H%M%S"`.log"
# strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 64 | tr -d '\n' > .restic-password
# chmod 400 .restic-password
# touch .restic-ignores
mkdir -p /var/log/restic
touch $LOGFILE
echo "Start: $(date)" >> $LOGFILE
echo "--------------------------------------" >> $LOGFILE
find /var/log/restic/ -mtime +45 -delete
/usr/bin/restic \
--quiet --repo $REPO_URL \
--password-file=/root/.restic-password snapshots >> $LOGFILE 2>&1 \
\
|| \
/usr/bin/restic --repo $REPO_URL \
--password-file=/root/.restic-password init | tee -a $LOGFILE
/usr/bin/restic \
forget --keep-last 75 --prune \
--password-file=/root/.restic-password \
--repo $REPO_URL >> $LOGFILE 2>&1
/usr/bin/restic \
--repo $REPO_URL \
backup /home \
--password-file=/root/.restic-password \
--exclude-file=/root/.restic-ignores \
--exclude=.venv --exclude=.pyenv --exclude="*.sock" \
--exclude-caches \
--verbose=0 >> $LOGFILE 2>&1
echo "--------------------------------------" >> $LOGFILE
echo "Finished: $(date)" >> $LOGFILE
curl -s -o /dev/null -X POST --data-binary @$LOGFILE https://canary.cruncher.ch/report/$CANARY_HASH/?result=$LOGFILE >> $LOGFILE 2>&1