|
|
@@ -0,0 +1,42 @@
|
|
|
+#!/bin/bash
|
|
|
+#########################################################################
|
|
|
+# Script for main backup PVE #
|
|
|
+# Created by DoIT #
|
|
|
+# ver 0.1 #
|
|
|
+#########################################################################
|
|
|
+
|
|
|
+#------------------------------- VARIABLE ------------------------------#
|
|
|
+DAT=$(date +%y%m%d)
|
|
|
+SRV=$(hostname -s)
|
|
|
+LST="30"
|
|
|
+
|
|
|
+#------------------------------- STORAGE ------------------------------#
|
|
|
+check(){
|
|
|
+test -f /usr/bin/pvesh || echo -e "- \e[1;31mNOT\e[0m right server [\e[1;33m$SRV\e[0m]"
|
|
|
+test -f /usr/bin/pvesh || sed -i '/pve_main_bck/d' /etc/crontab
|
|
|
+test -f /usr/bin/pvesh || exit 0
|
|
|
+DST=$(df -h | egrep "backup|Synology|NAS|usb" | awk '{print $NF}')
|
|
|
+test -d $DST/pve || mkdir $DST/pve
|
|
|
+}
|
|
|
+
|
|
|
+#------------------------------- BACKUP -------------------------------#
|
|
|
+backup(){
|
|
|
+echo -e "- \e[1;32mBackuping\e[0m [\e[1;33mPVE\e[0m] \e[1;32mconfigurations\e[0m"
|
|
|
+tar czf $DST/pve/pve_config_${SRV}_${DAT}.tar.gz /etc/pve/ > /dev/null 2>&1
|
|
|
+echo -e "- \e[1;32mRemoving\e[0m [\e[1;33m$LST\e[0m] \e[1;32mdays old configurations\e[0m"
|
|
|
+find $DST/pve/ -type f -mtime +30 -delete
|
|
|
+echo -e "- \e[1;32mBackup Location\e[0m [\e[1;34m$DST/pve/\e[0m]:"
|
|
|
+ls -laftr $DST/pve/ | grep "$(date +%y%m)" | tail -3
|
|
|
+}
|
|
|
+
|
|
|
+#------------------------------- BACKUP -------------------------------#
|
|
|
+restore(){
|
|
|
+scp NAS:/pve_config_###.tar.gz /opt/
|
|
|
+tar xzf /opt/pve_config_###.tar.gz -C /
|
|
|
+systemctl restart pve-cluster
|
|
|
+}
|
|
|
+
|
|
|
+#------------------------------- CORE ----------------------------------#
|
|
|
+clear
|
|
|
+check
|
|
|
+backup
|