forked from m4r1oph/Synology-vmm-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynology-vmm-backup.sh
32 lines (28 loc) · 1.75 KB
/
Synology-vmm-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
#!/bin/bash
synowebapi --exec api=SYNO.Virtualization.API.Guest.Action version=1 method=shutdown runner=admin guest_name="NAME_OF_VM"
sleep 15m
/var/packages/Virtualization/target/bin/vmm_backup_ova --dst=Backup --batch=1 --guests="NAME_OF_VM"
mv $(find /ROUTE/TO/THE/DESTINATION/FOLDER -maxdepth 1 -type f ! -name '.*' ! -name 'NAME_OF_VM*') /ROUTE/TO/THE/DESTINATION/FOLDER/NoBackups
num_backups=$(find /ROUTE/TO/THE/DESTINATION/FOLDER -maxdepth 1 -type f ! -name '.*' | wc -l)
if [[ $num_backups -gt 3 ]]
then
mkdir /ROUTE/TO/THE/DESTINATION/FOLDER/logs
backup_old=$(find /ROUTE/TO/THE/DESTINATION/FOLDER -maxdepth 1 -type f -printf '%T+ %p\n' | sort > /ROUTE/TO/THE/DESTINATION/FOLDER/logs/fich.txt)
num_lin=$(cat /ROUTE/TO/THE/DESTINATION/FOLDER/logs/fich.txt | wc -l )
num_old=$(($num_lin-3))
if [[ $num_old -gt 0 ]]
then
num_delete=$(($num_old+1))
cat /ROUTE/TO/THE/DESTINATION/FOLDER/logs/fich.txt | head -n $num_old | cut -d " " -f 2 > /ROUTE/TO/THE/DESTINATION/FOLDER/logs/del_old.txt
num_lin=$(cat /ROUTE/TO/THE/DESTINATION/FOLDER/logs/del_old.txt | wc -l )
for i in $(seq 1 $num_lin)
do
delete=$(cat /ROUTE/TO/THE/DESTINATION/FOLDER/logs/del_old.txt | sed -n $i'p')
rm $delete
done
fi
rm -r /ROUTE/TO/THE/DESTINATION/FOLDER/logs
fi
hyper_backup=$(find /ROUTE/TO/THE/DESTINATION/FOLDER -maxdepth 1 -type f -printf '%T+ %p\n' | sort | tail -n 1 | cut -d " " -f 2)
cp $hyper_backup /ROUTE/TO/THE/DESTINATION/FOLDER/HyperBackup/WS.ova
synowebapi --exec api=SYNO.Virtualization.API.Guest.Action version=1 method=poweron runner=admin guest_name="NAME_OF_VM"