Admin Backup

ben29

Verified User
Joined
Jul 20, 2006
Messages
449
Location
Israel
when admin do backup, it's useful to do clock with the backup
that mean when admin do backup on
/admin_backups
it's will do auto date like, /admin_backups/1-1-2010
by def
 
Yes it should be useful, but is not that hard to write your own script that 5mins before backup (or the day after a cron backup) create the folder for you.

Not sure, but aswell should be useful a create_backup_post.sh and create_backup_pre.sh so this can be a little automatized without much pain.

Regards
 
Ok, ive checked, the feature for post backup exist.

just create

Code:
/usr/local/directadmin/scripts/custom/user_backup_post.sh

And create in there the code to create a new folder and just move the just made backups in there.

If you wanna mange some stuff to do before a backup start there is also:
Code:
/usr/local/directadmin/scripts/custom/user_backup_pre.sh

Regards
 
On user_backup_post.sh i would use something like this:

Code:
mkdir /home/admin/admin_backups_$(date +\%m_\%d_\%Y)
mv /home/admin/admin_backups/* /home/admin/admin_backups_$(date +\%m_\%d_\%Y)


This should work and create an admin_backup_DATE directory in /home/admin and move all backuped account from the standard admin_backups (that cannot be deleted) to the new just created admin_backup_DATE

Of coruse, DATE will take the current system date in this format: m/d/Y (today so would be 11/06/2011)

Regards
 
Yep sorry, was meaning the month/day/year format.. cause here in Italy we do use day/month/year, i wansnt meaning the directory name :)

Regards
 
Also ive noticed that this script is run everytime an any kind/level backup is started it start...

So, this would start on user backup aswell and this script will just create empty folder sometimes, would be much more usefull to have something like those two file just for admin level and reseller level aswell.

Regards
 
To sort directories quickly it would be better to use YEAR/MONTH/DATE. Thus within YEAR/MONTH/ you'll get all backups of all days of the specified month.
 
mmmh yep, you are right.

Ill test this way, but, i know there is a way with an if in bash scripting to check if a directory/file exist (so i can skil year and/or month if they exist) do you know how is composed the if (ofc i should check on googlee aswell ^^ )

Regards
 
Something like this:

if [ -d "/full/path/to/directory" ]; then
....
else
....
mkdir -p /full/path/to/directory
....
fi;
 
Thanks :) i had found it aswell, i would need a suggestion by you, do you think this would work well or can be done better?

Code:
if [ -d /backup/$(date +\%Y) ]; then

        if [ -d /backup/$(date +\%Y)/$(date +\%m) ]; then

                if [ -d /backup/$(date +\%Y)/$(date +\%m)/$(date +\%d) ]; then

                else

                        mkdir /backup/$(date +\%Y)/$(date +\%m)/$(date +\%d)

                fi

        else

                mkdir /backup/$(date +\%Y)/$(date +\%m)
                mkdir /backup/$(date +\%Y)/$(date +\%m)/$(date +\%d)


        fi

else

        mkdir /backup/$(date +\%Y)
        mkdir /backup/$(date +\%Y)/$(date +\%m)
        mkdir /backup/$(date +\%Y)/$(date +\%m)/$(date +\%d)

fi

Thanks
 
Your code can be shortened

Code:
DIR=/backup/`date +%Y/%m/%d`
if [ ! -d $DIR ]; then

mkdir -p $DIR;

fi;

That's it.
 
Ah... lol... thanks a lot! i always sayd im not a programmer and this is the best proof... ive used 20 line for a job done in 3 :D

Actually, didnt know that an mkdir with subfolder was going to work :D

Thanks a lot
 
That's OK.

Taken from man mkdir:

Code:
       -p, --parents
              no error if existing, make parent directories as needed
 
Very interesting.

My backup script actually have this function also:

Code:
find /backup/ -mtime +10 -delete

for remove 10-day older backup... So here my question, does thi will delete the folder (for example 2011) too cause is 10 day old? cause in this case for example he must keep year and month unless (at least) they arent empty.

have you any suggestion for this?

Thanks
 
Directory can not be removed until it's empty by default. And you'll get something like:

find: cannot delete /backup/path/to/dir: Directory not empty
find: cannot delete /backup/path/to: Directory not empty
 
Back
Top