forked from TheRealAlexV/proxmox-vzbackup-rclone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvzbackup-rclone.sh
executable file
·94 lines (79 loc) · 3.01 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
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# ./vzbackup-rclone.sh rehydrate
############ /START CONFIG
dumpdir="/mnt/pve/backups/dump" # Set this to where your vzdump files are stored
rcremote="pcloud" # Set this to your rclone remote
# 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"
remotevzdumpsdir="vzdumps"
remoteenvdir="env"
COMMAND=${1}
tarfile=${TARFILE}
exten=${tarfile#*.}
filename=${tarfile%.*.*}
if [[ ${COMMAND} == 'rehydrate' ]]; then
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M copy $rcremote:/$remotevzdumpsdir $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} == 'env-backup' || ${COMMAND} == 'full-backup' ]]; then
echo "Backing up main PVE configs"
echo "Creating ramdisk to hold the backup files"
mkdir -p /mnt/ramdisk
mount -t tmpfs -o size=2G tmpfs /mnt/ramdisk
_tdir=${TMP_DIR:-/mnt/ramdisk}
_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/proxmox_etc.$_now.tar"
_filename2="$_tdir/proxmox_pve.$_now.tar"
_filename3="$_tdir/proxmox_root.$_now.tar"
_filename4="$_tdir/proxmox_gpuroms.$_now.tar"
_filename_all="$_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/.
tar --warning='no-file-ignored' -cPf "$_filename4" /usr/share/kvm/gpuroms/.
echo "Compressing files"
# archive the copied system files
tar -cvzPf "$_filename_all" -C $_tdir/ .
currentDir=${pwd}
cd $_tdir
echo "rcloning $_filename_all"
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M move $_filename_all $rcremote:/$remoteenvdir \
-v --stats=60s --transfers=16 --checkers=16
cd $currentDir
umount /mnt/ramdisk/
fi
if [[ ${COMMAND} == 'dump-backup' || ${COMMAND} == 'full-backup' || ${COMMAND} == 'job-end' || ${COMMAND} == 'job-abort' ]]; then
# Upload vzdumps
cd $dumpdir
echo "rcloning vzdumps"
rclone_upload () {
for i in $1; do
[ -f "$i" ] || break
echo "rcloning $i"
rclone --config /root/.config/rclone/rclone.conf \
--drive-chunk-size=32M copy $i $rcremote:/$remotevzdumpsdir \
-v --stats=60s --transfers=16 --checkers=16
done
}
rclone_upload "*.vma.zst"
rclone_upload "*.notes"
fi