Last active
February 28, 2022 11:43
-
-
Save kavibritto/27010b2c8bc61ddce4ad222e2eb6684f to your computer and use it in GitHub Desktop.
this snippet helps you to enable DIGITALOCEAN SPACES backup in vestacp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spaces_backup() { | |
# Defining google settings | |
#source $VESTA/conf/space.backup.conf | |
export END_POINT=<ENTER THE ENDPOINT> | |
export AWS_ACCESS_KEY_ID=<ENTER THE AWS ACCESS KEY> | |
export AWS_SECRET_ACCESS_KEY=<ENTER THE AWS SECRET KEY> | |
BUCKET=<YOUR BUCKET NAME HERE> | |
BPATH=<DESTINATION PATH> | |
gsutil="aws s3 --endpoint=${END_POINT}" | |
export BOTO_CONFIG="$VESTA/conf/.space.backup.boto" | |
# Debug info | |
echo -e "$(date "+%F %T") Remote: s3://$BUCKET/$BPATH/$user.$backup_new_date.tar" | |
# Checking retention | |
# echo "aws s3 --endpoint=${END_POINT} ls s3://$BUCKET/$BPATH/$user.* 2>/dev/null" | |
backup_list=$(aws s3 --endpoint=${END_POINT} ls s3://$BUCKET/$BPATH/$user.* 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 | |
echo -e "$(date "+%F %T") Rotated spaces backup: $backup" | |
aws s3 --endpoint=${END_POINT} rm $backup > /dev/null 2>&1 | |
done | |
fi | |
# Uploading backup archive | |
echo -e "$(date "+%F %T") Uploading $user.$backup_new_date.tar ..." | |
if [ "$localbackup" = 'yes' ]; then | |
cd $BACKUP | |
aws s3 --endpoint=${END_POINT} cp $user.$backup_new_date.tar s3://$BUCKET/$BPATH/ > /dev/null 2>&1 | |
else | |
cd $tmpdir | |
tar -cf $BACKUP/$user.$backup_new_date.tar . | |
cd $BACKUP/ | |
# echo "aws s3 --endpoint=${END_POINT} cp $user.$backup_new_date.tar s3://$BUCKET/$BPATH/" | |
aws s3 --endpoint=${END_POINT} cp /backup/$user.$backup_new_date.tar s3://$BUCKET/$BPATH/ > /dev/null 2>&1 | |
rc=$? | |
rm -rf $user.$backup_new_date.tar | |
rm -rf $tmpdir | |
if [ "$rc" -ne 0 ]; then | |
check_result "$E_CONNECT" "spaces failed to upload $user.$backup_new_date.tar" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add this snippet after google_backup() block and make sure add the line in switch case( Refer the image.)
And make sure you changed backup option to spaces in config/vesta.conf location