Просмотр исходного кода

Add b2 support to v-delete-user-backup (#2253)

* Add b2 support to v-delete-user-backup

* Adress mistake made in 

https://github.com/hestiacp/hestiacp/blame/e2d7eb9da2af4372d8f11b07ad3a56cf3da970bb/func/backup.sh#L437
+ https://github.com/hestiacp/hestiacp/blame/e2d7eb9da2af4372d8f11b07ad3a56cf3da970bb/func/backup.sh#L442

Adjusted v-delete-user-backup accordingly

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Wojciech Smoliński 4 лет назад
Родитель
Сommit
5747cfa076
2 измененных файлов с 17 добавлено и 2 удалено
  1. 4 0
      bin/v-delete-user-backup
  2. 13 2
      func/backup.sh

+ 4 - 0
bin/v-delete-user-backup

@@ -57,10 +57,14 @@ fi
 if [[ "$TYPE" =~ "ftp" ]] && [ "$deleted" == "0" ]; then
     ftp_delete "$backup"
 fi
+if [[ "$TYPE" =~ "b2" ]]; then
+    b2_delete "$user" "$backup"
+fi
 if [[ "$TYPE" =~ "local" ]]; then
     rm -f "$backup_folder/$2"
 fi
 
+
 # Deleting backup
 sed -i "/BACKUP='$2' /d" "$USER_DATA/backup.conf"
 

+ 13 - 2
func/backup.sh

@@ -434,12 +434,12 @@ b2_backup() {
     echo -e "$(date "+%F %T") Upload to B2: $user/$user.$backup_new_date.tar"
     if [ "$localbackup" = 'yes' ]; then
         cd $BACKUP
-        b2 upload-file $BUCKET $user.$backup_new_date.tar $user/$user.tar
+        b2 upload-file $BUCKET $user.$backup_new_date.tar $user/$user.$backup_new_date.tar > /dev/null 2>&1
     else
         cd $tmpdir
         tar -cf $BACKUP/$user.$backup_new_date.tar .
         cd $BACKUP/
-        b2 upload-file $BUCKET $user.$backup_new_date.tar $user/$user.tar
+        b2 upload-file $BUCKET $user.$backup_new_date.tar $user/$user.$backup_new_date.tar > /dev/null 2>&1
         rc=$?
         rm -f $user.$backup_new_date.tar
         if [ "$rc" -ne 0 ]; then
@@ -472,4 +472,15 @@ b2_download() {
     if [ "$?" -ne 0 ]; then
     check_result "$E_CONNECT" "b2 failed to download $user.$1"
     fi
+}
+
+b2_delete(){
+    # Defining backblaze b2 settings
+    source_conf "$HESTIA/conf/b2.backup.conf"
+    
+    # Recreate backblaze auth file ~/.b2_account_info (for situation when key was changed in b2.backup.conf)
+    b2 clear-account > /dev/null 2>&1
+    b2 authorize-account $B2_KEYID $B2_KEY > /dev/null 2>&1
+
+    b2 delete-file-version $1/$2 > /dev/null 2>&1
 }