-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote-encrypt-backup
More file actions
executable file
·74 lines (62 loc) · 2.04 KB
/
Copy pathremote-encrypt-backup
File metadata and controls
executable file
·74 lines (62 loc) · 2.04 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# This script was created to make Duplicity backups.
# Full backups are done once every 3 months.
# Incremental backups are made every other day.
# Check for the number of arguments
if [ $# != 4 ]; then
echo "Usage: remote-backup <backup-code> <source> <target> <backup-frequency>"
exit 1
fi
wget -q --tries=10 --timeout=20 --spider http://google.com
if [ $? != 0 ]; then
echo "Error: Host is not online"
exit 2
fi
LOG_DIR=/var/log/duplicity
CODE=$1
SOURCE=$2
TARGET=$3
FREQUENCY=$4
# Flags to exclude some dotfiles
if [ $CODE == "dotfiles" ]; then
FLAGS=" --exclude **$HOME/.cache/** \
--exclude **$HOME/.gem/** \
--exclude **$HOME/.local/share/lutris/** \
--exclude **$HOME/.local/lib/** \
--exclude **$HOME/.wine/** \
--exclude **$HOME/.local/share/libvirt/** \
--exclude **$HOME/.local/share/baloo/** \
--exclude **$HOME/.local/share/Steam/** \
--exclude **$HOME/.local/share/vocal/** \
--exclude **$HOME/.vagrant.d/** \
--include **$HOME/.** \
--exclude **\*"
elif [ $CODE == "documents" ]; then
FLAGS=" --exclude **$HOME/Documents/LEI** \
--exclude **$HOME/Documents/Jobs**"
else
unset FLAGS
fi
# Variable to define the xorg session
export DISPLAY=:0
# Setting the passphrase to encrypt the backup files.
# Get the passphrase from kwallet.
export PASSPHRASE=`kwallet-query kdewallet -f Passwords -r $CODE`
# --------- FOR DEBUGGING ------------
# duplicity --dry-run --verbosity 8 --allow-source-mismatch --full-if-older-than $FREQUENCY $FLAGS $SOURCE $TARGET
# Backup files
duplicity --full-if-older-than $FREQUENCY $FLAGS $SOURCE $TARGET >> $LOG_DIR/$CODE.log 2>&1
if [ $? != 0 ]; then
MESSAGE="Error code: $?. $(date +'%d %b %Y %H:%M')-- Error performing the $CODE backup."
else
MESSAGE="$(date +'%d %b %Y %H:%M')-- Finished execution of remote $CODE backup."
fi
echo $MESSAGE >> $LOG_DIR/$CODE.log 2>&1
# Delete older backups then 3 months
duplicity remove-older-than 3M \
--force \
$TARGET >> $LOG_DIR/$CODE.log 2>&1
# Unsetting the confidential variables so they are gone for sure.
unset PASSPHRASE
exit 0