Update v-backup-user

I noticed that I always seemed to have 1 less backup than I was supposed to in my VestaCP. This fix resolves the issue for me.


Problem outlined:

- My VestaCP package says that I'm supposed to be allowed 3 backups.
- The backups tab of the GUI showed that I had 3 backups.
- I was never able to access the oldest backup (Almost like it wasn't actually there).
- I checked the backup folder using SSH and I found that I only ever have the latest 2 backups available.
- It was clear that a script was deleting the 3rd backup prematurely.
This commit is contained in:
cmstew 2017-07-21 10:58:21 -06:00 committed by GitHub
commit e71a1619f0

View file

@ -483,7 +483,6 @@ local_backup(){
backups_count=$(echo "$backup_list" |wc -l) backups_count=$(echo "$backup_list" |wc -l)
if [ "$BACKUPS" -le "$backups_count" ]; then if [ "$BACKUPS" -le "$backups_count" ]; then
backups_rm_number=$((backups_count - BACKUPS)) backups_rm_number=$((backups_count - BACKUPS))
(( ++backups_rm_number))
# Removing old backup # Removing old backup
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
@ -599,7 +598,7 @@ ftp_backup() {
fi fi
backups_count=$(echo "$backup_list" |wc -l) backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS + 1)) backups_rm_number=$((backups_count - BACKUPS))
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//") backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar$//")
echo -e "$(date "+%F %T") Rotated ftp backup: $backup_date" |\ echo -e "$(date "+%F %T") Rotated ftp backup: $backup_date" |\
@ -754,7 +753,7 @@ sftp_backup() {
fi fi
backups_count=$(echo "$backup_list" |wc -l) backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS + 1)) backups_rm_number=$((backups_count - BACKUPS))
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar.*$//") backup_date=$(echo $backup |sed -e "s/$user.//" -e "s/.tar.*$//")
echo -e "$(date "+%F %T") Rotated sftp backup: $backup_date" |\ echo -e "$(date "+%F %T") Rotated sftp backup: $backup_date" |\
@ -803,7 +802,7 @@ google_backup() {
backup_list=$(${gsutil} ls gs://$BUCKET/$BPATH/$user.* 2>/dev/null) backup_list=$(${gsutil} ls gs://$BUCKET/$BPATH/$user.* 2>/dev/null)
backups_count=$(echo "$backup_list" |wc -l) backups_count=$(echo "$backup_list" |wc -l)
if [ "$backups_count" -ge "$BACKUPS" ]; then if [ "$backups_count" -ge "$BACKUPS" ]; then
backups_rm_number=$((backups_count - BACKUPS + 1)) backups_rm_number=$((backups_count - BACKUPS))
for backup in $(echo "$backup_list" |head -n $backups_rm_number); do for backup in $(echo "$backup_list" |head -n $backups_rm_number); do
echo -e "$(date "+%F %T") Roated gcp backup: $backup" echo -e "$(date "+%F %T") Roated gcp backup: $backup"
$gsutil rm $backup > /dev/null 2>&1 $gsutil rm $backup > /dev/null 2>&1