ramirojoaquin / vestacp-borg-incremental-backups

A series of bash scripts to perform incremental backups of Vesta Control Panel users and server config, using Borg Backup as backend.
GNU General Public License v3.0
23 stars 15 forks source link

FIXED: Excluding /home/backup dir from backup-execute.sh #1

Closed agapiospanos closed 5 years ago

agapiospanos commented 5 years ago

Thank you for this great script. It is really awesome.

I have a suggestion to make. When I run the script backup-execute.sh I notice that it also backups the /home/backup directory which is the directory that vesta's default backup system is generating the tar files for the complete backups. I think that this dir should be excluded from the borg backup procedure. I know that if someone uses borg he will disable vesta's backup system and this dir will be empty but in my case I kept both for some days just to be sure that everything is working as expected.

I tried adding the --exclude /home/backup and --exclude 'home-backup' argument in the OPTIONS_CREATE var of the config.ini file but it did not work and the backup dir was still backed up with borg.

Thus I came to a solution of modifying the line 28 in backup execute script as follows

from

if [ -d "$USER_DIR" ]; then

to

if [ -d "$USER_DIR" ] && [ "$USER_DIR" != "/home/backup" ]
  then

Do you think there is a more proper way of doing this? Should we add a var like EXCLUDED_DIRS to config.ini so that we can add there the excluded dirs and keep the sh scripts clean?

Thank you! :)

ramirojoaquin commented 5 years ago

Thanks for your suggestion Agapos! In Debian (the OS that i use) the default vesta dir for backups is /backup and not /home/backup If you ask me, i would prefer to keep backup dir out of home dir. Because, in linux systems home dir is dedicated to users dirs only, and because is more organized that way. Vesta allows you to change the default backup destination dir.

I also use for a while the two backups systems at the same time, and my dir config was /backup/borg for incremental backups and /backup/vesta for vesta backups.

In the case you dont want to change the backup dir the solution that you propose is OK, Maybe we can add a variable called "GLOBAL_EXCLUDE" and put there a series of dirs that we dont want to backup, and in the if statement compare the user dir that is going to be backed up with the array of global exclusions, and proceed only if the dir is not present on that array (the GLOBAL_EXCLUDE should be placed in config.ini). That way is more flexible.

By the way, the OPTIONS_CREATE are reused in every user backup execution. So, when you add --exclude /home/backup the final command for that dir is: borg create -sv --compression lz4 --exclude /home/backup /backup/borg/home/backup::2018-11-29 /home/backup --exclude-from=$EXCLUDE

So, this doesnt work because you are basically telling borg to exclude the same directory that you telling him to backup...

Sorry if i misspell some words, english is not my native language :)

ramirojoaquin commented 5 years ago

Check my last commit, i add the functionality of Excluded Users list, in config.ini and in backup-execute.sh

agapiospanos commented 5 years ago

Thank you for the quick response!!

You are right that the backup dir is better if it is outside home dir. I will move it to root. I use centos 7 and vesta was configured this way by default and I didn't make changes..

I saw the changes in your last commit and it is exactly what I had in my mind! Great implementation!

As for the explanation about why --exclude did not work for me, your explanation seems really reasonable! Thank you!

Keep up the good work!

Cheers, Agapios