-
Notifications
You must be signed in to change notification settings - Fork 85
/
vzbackup-rclone.sh
executable file
·84 lines (74 loc) · 2.91 KB
/
vzbackup-rclone.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# ./vzbackup-rclone.sh rehydrate YYYY/MM/DD file_name_encrypted.bin
############ /START CONFIG
dumpdir="/mnt/pve/pvebackups01/dump" # Set this to where your vzdump files are stored
MAX_AGE=3 # This is the age in days to keep local backup copies. Local backups older than this are deleted.
############ /END CONFIG
_bdir="$dumpdir"
rcloneroot="$dumpdir/rclone"
timepath="$(date +%Y)/$(date +%m)/$(date +%d)"
rclonedir="$rcloneroot/$timepath"
COMMAND=${1}
rehydrate=${2} #enter the date you want to rehydrate in the following format: YYYY/MM/DD
if [ ! -z "${3}" ];then
CMDARCHIVE=$(echo "/${3}" | sed -e 's/\(.bin\)*$//g')
fi
tarfile=${TARFILE}
exten=${tarfile#*.}
filename=${tarfile%.*.*}
if [[ ${COMMAND} == 'rehydrate' ]]; then
#echo "Please enter the date you want to rehydrate in the following format: YYYY/MM/DD"
#echo "For example, today would be: $timepath"
#read -p 'Rehydrate Date => ' rehydrate
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M copy gd-backup_crypt:/$rehydrate$CMDARCHIVE $dumpdir \
-v --stats=60s --transfers=16 --checkers=16
fi
if [[ ${COMMAND} == 'job-start' ]]; then
echo "Deleting backups older than $MAX_AGE days."
find $dumpdir -type f -mtime +$MAX_AGE -exec /bin/rm -f {} \;
fi
if [[ ${COMMAND} == 'backup-end' ]]; then
echo "Backing up $tarfile to remote storage"
#mkdir -p $rclonedir
#cp -v $tarfile $rclonedir
echo "rcloning $rclonedir"
#ls $rclonedir
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M copy $tarfile gd-backup_crypt:/$timepath \
-v --stats=60s --transfers=16 --checkers=16
fi
if [[ ${COMMAND} == 'job-end' || ${COMMAND} == 'job-abort' ]]; then
echo "Backing up main PVE configs"
_tdir=${TMP_DIR:-/var/tmp}
_tdir=$(mktemp -d $_tdir/proxmox-XXXXXXXX)
function clean_up {
echo "Cleaning up"
rm -rf $_tdir
}
trap clean_up EXIT
_now=$(date +%Y-%m-%d.%H.%M.%S)
_HOSTNAME=$(hostname -f)
_filename1="$_tdir/proxmoxetc.$_now.tar"
_filename2="$_tdir/proxmoxpve.$_now.tar"
_filename3="$_tdir/proxmoxroot.$_now.tar"
_filename4="$_tdir/proxmox_backup_"$_HOSTNAME"_"$_now".tar.gz"
echo "Tar files"
# copy key system files
tar --warning='no-file-ignored' -cPf "$_filename1" /etc/.
tar --warning='no-file-ignored' -cPf "$_filename2" /var/lib/pve-cluster/.
tar --warning='no-file-ignored' -cPf "$_filename3" /root/.
echo "Compressing files"
# archive the copied system files
tar -cvzPf "$_filename4" $_tdir/*.tar
# copy config archive to backup folder
#mkdir -p $rclonedir
cp -v $_filename4 $_bdir/
#cp -v $_filename4 $rclonedir/
echo "rcloning $_filename4"
#ls $rclonedir
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M move $_filename4 gd-backup_crypt:/$timepath \
-v --stats=60s --transfers=16 --checkers=16
#rm -rfv $rcloneroot
fi