How to make automated backup using PAX and Crontab
TAGS: Script, PAX, Shell, Linux, Crontab

If you found the last posting interesting, then I am sure you will like this one also.
We made a script that makes use of PAX, a commandline tool, for making backup of our projects.

Now we will make cronjobs for executing those scripts, so that we totally automize the backup procedures on our machine.

Lets recall our script..

cd /home/you/lampstack/apache2/htdocs/project 
rm backup.pax 
pax -wzf backup.pax . 
cp backup.pax /home/you/backup/project/$(date +%F).pax 

About crontab: cron is the system process which will automatically perform tasks for you according to a set schedule. The schedule is called the crontab, which is also the name of the program used to edit that schedule. (Cite from the website linked to at the end of this text). Here is how the crontab entry looks if we want to execute our script every hour at 15 minutes past the hour.
15 *  * * * /home/you/programs/scripts/

Here we execute the same cronjob every workday of the week at 15 minutes past 8 (AM).
15 8  * * 1-5 /home/you/programs/scripts/

A cronjob consist of 6 entries.

The first is Minutes (0-59)
The second is for hours (0-23)
Third is day of month (1-31)
Fourth entry is month (1-12)
Fifth is day of week (0-7)
Sixth is the path to the scriptfile to run.

Notice that in the fifth both 0 an 7 are Sundays.

Okay. So we have the information we need to build our automated backup scripts. I assume that we use the script as seen above. And that we use the second example of the cronjob also above here. Now we need to enter the job into the crontab. We can do that easliy. Write in the following in your terminal:

$ crontab -e

.. this will open the nano editor with the crontab config file.
I made two screenshots of the nano editor, you see those here:

As you can see, the bottomline in the third shot show our entry into the crontab.

When you have written the line into nano end by hitting CTRL-X. The nano editor will ask you if you want to save. Hit Y (yes), and then A (append).
Your cronjob should have been added now. You can check it by typing this:

cronjob -l

Remember to look at:

man crontab

Now your system will create a backup every workday at 15 minutes pass 8 o'clock.

I have chosen a link for more information. Look at: