Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Backblaze B2 experimental backup support #1848

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions bin/v-backup-user
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,45 @@ google_backup() {
fi
}

# BackBlaze B2 backup function
backblazeb2_backup() {
# Defining backblaze b2 settings
source $VESTA/conf/b2.backup.conf
b2util=$(which b2)
# Recreate backblaze auth file ~/.b2_account_info (for situation when key was changed in b2.backup.conf)
$b2util clear-account > /dev/null 2>&1
$b2util authorize-account $B2_KEYID $B2_KEY > /dev/null 2>&1

# Checking retention
backup_list=$(${b2util} ls --long $BUCKET $user | cut -f 1 -d ' ' 2>/dev/null)
backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS))
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_file_name=$($b2util get-file-info $backup | grep fileName | cut -f 4 -d '"' 2>/dev/null)
echo -e "$(date "+%F %T") Rotated b2 backup: $backup_file_name"
$b2util delete-file-version $backup > /dev/null 2>&1
done
fi

# Uploading backup archive
echo -e "$(date "+%F %T") Uploading $user/$user.$backup_new_date.tar ..."
if [ "$localbackup" = 'yes' ]; then
cd $BACKUP
${b2util} 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/
${b2util} 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
check_result "$E_CONNECT" "b2 failed to upload $user.$backup_new_date.tar"
fi
fi
}


echo -e "\n-- SUMMARY --" |tee -a $BACKUP/$user.log

Expand All @@ -869,6 +908,7 @@ for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
ftp) ftp_backup ;;
sftp) sftp_backup ;;
google) google_backup ;;
b2) backblazeb2_backup ;;
esac
done

Expand Down
28 changes: 26 additions & 2 deletions bin/v-delete-user-backup
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ backup=$(echo $2| cut -f 2 -d \.)
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf

backblazeb2_delete() {
# Defining backblaze settings
source $VESTA/conf/b2.backup.conf
b2util=$(which b2)
# Recreate backblaze auth file ~/.b2_account_info (for situation when key was changed in b2.backup.conf)
$b2util clear-account > /dev/null 2>&1
$b2util authorize-account $B2_KEYID $B2_KEY > /dev/null 2>&1

# Define file id in b2 by backup file name
backup_file_id=$(${b2util} ls --long $BUCKET $user | grep "$backup" | cut -f 1 -d ' ' 2>/dev/null)
# Deleting file in b2
${b2util} delete-file-version $backup_file_id > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
check_result "$E_CONNECT" "b2 failed to delete $1"
fi
}

#----------------------------------------------------------#
# Verifications #
Expand All @@ -33,8 +49,16 @@ is_object_valid 'backup' 'BACKUP' "$2"
# Action #
#----------------------------------------------------------#

# Deleting backup
rm -f $BACKUP/$2
# Delete local/remote backups
if [ ! -e "$BACKUP/$backup" ]; then
if [[ "$BACKUP_SYSTEM" =~ "b2" ]]; then
backblazeb2_delete $2
fi
if [[ "$BACKUP_SYSTEM" =~ "local" ]]; then
rm -f $BACKUP/$2
fi
fi

sed -i "/BACKUP='$2' /d" $USER_DATA/backup.conf


Expand Down
18 changes: 18 additions & 0 deletions bin/v-restore-user
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ google_download() {
fi
}

# BackBlaze B2 backup download function
backblazeb2_download() {
# Define b2 settings
source $VESTA/conf/b2.backup.conf
b2util=$(which b2)
# Recreate backblaze auth file ~/.b2_account_info (for situation when key was changed in b2.backup.conf)
$b2util clear-account > /dev/null 2>&1
$b2util authorize-account $B2_KEYID $B2_KEY > /dev/null 2>&1
#Download backup file from b2
${b2util} download-file-by-name --noProgress $BUCKET $user/$backup $BACKUP/$backup > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
check_result "$E_CONNECT" "b2 failed to download $1"
fi
}

#----------------------------------------------------------#
# Verifications #
Expand All @@ -180,6 +194,10 @@ if [ ! -e "$BACKUP/$backup" ]; then
google_download $backup
downloaded='yes'
fi
if [[ "$BACKUP_SYSTEM" =~ "b2" ]]; then
backblazeb2_download $backup
downloaded='yes'
fi
if [[ "$BACKUP_SYSTEM" =~ "sftp" ]] && [ -z "$downloaded" ]; then
sftp_download $backup
downloaded='yes'
Expand Down