From a33eaef5f0b3efafb52999a17f439b7570d7089f Mon Sep 17 00:00:00 2001 From: Ali Chopani <58507994+ach1992@users.noreply.github.com> Date: Mon, 28 Aug 2023 03:51:46 +0330 Subject: [PATCH] Update backup.sh Add MySQL backup for Marzban --- backup.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/backup.sh b/backup.sh index d709de4..efe60aa 100644 --- a/backup.sh +++ b/backup.sh @@ -3,7 +3,8 @@ # Bot token # گرفتن توکن ربات از کاربر و ذخیره آن در متغیر tk while [[ -z "$tk" ]]; do - read -p 'Bot token: ' tk + echo "Bot token: " + read -r tk if [[ $tk == $'\0' ]]; then echo "Invalid input. Token cannot be empty." unset tk @@ -13,7 +14,8 @@ done # Chat id # گرفتن Chat ID از کاربر و ذخیره آن در متغیر chatid while [[ -z "$chatid" ]]; do - read -p 'Chat id: ' chatid + echo "Chat id: " + read -r chatid if [[ $chatid == $'\0' ]]; then echo "Invalid input. Chat id cannot be empty." unset chatid @@ -25,12 +27,14 @@ done # Caption # گرفتن عنوان برای فایل پشتیبان و ذخیره آن در متغیر caption -read -p 'Caption (for example, your domain, to identify the database file more easily): ' caption +echo "Caption (for example, your domain, to identify the database file more easily): " +read -r caption # Cronjob # تعیین زمانی برای اجرای این اسکریپت به صورت دوره‌ای while true; do - read -p 'Cronjob (minutes and hours) (e.g : 30 6 or 0 12) : ' minute hour + echo "Cronjob (minutes and hours) (e.g : 30 6 or 0 12) : " + read -r minute hour if [[ $minute == 0 ]] && [[ $hour == 0 ]]; then cron_time="* * * * *" break @@ -52,7 +56,8 @@ done # x-ui or marzban or hiddify # گرفتن نوع نرم افزاری که می‌خواهیم پشتیبانی از آن بگیریم و ذخیره آن در متغیر xmh while [[ -z "$xmh" ]]; do - read -p 'x-ui or marzban or hiddify? [x/m/h] : ' xmh + echo "x-ui or marzban or hiddify? [x/m/h] : " + read -r xmh if [[ $xmh == $'\0' ]]; then echo "Invalid input. Please choose x, m or h." unset xmh @@ -63,7 +68,8 @@ while [[ -z "$xmh" ]]; do done while [[ -z "$crontabs" ]]; do - read -p 'Would you like the previous crontabs to be cleared? [y/n] : ' crontabs + echo "Would you like the previous crontabs to be cleared? [y/n] : " + read -r crontabs if [[ $crontabs == $'\0' ]]; then echo "Invalid input. Please choose y or n." unset crontabs @@ -90,16 +96,56 @@ else exit 1 fi +if [ -d "/var/lib/marzban/mysql" ]; then + + sed -i -e 's/\s*=\s*/=/' -e 's/\s*:\s*/:/' -e 's/^\s*//' /opt/marzban/.env + + docker exec marzban-mysql-1 bash -c "mkdir -p /var/lib/mysql/db-backup" + source /opt/marzban/.env + + cat > "/var/lib/marzban/mysql/ac-backup.sh" < /var/lib/mysql/db-backup/\$db.sql + + fi +done + +EOL +chmod +x /var/lib/marzban/mysql/ac-backup.sh + +ZIP=$(cat <//g;s/<\/code>//g') +comment=$(trim "$comment") # install zip # نصب پکیج zip @@ -153,10 +212,13 @@ sudo apt install zip -y # send backup to telegram # ارسال فایل پشتیبانی به تلگرام cat > "/root/ac-backup-${xmh}.sh" </dev/null 2>&1"; } | crontab -u root -