https://dev.webpages.dk/  
 
PHP How to use PAX for Backup
How to Backup files using PAX:

For backup, pax and cron is a match made in heaven.
You can, besides on your server, also use this on you desktop computer.
To the right of here you can see some examples on how to use PAX.

 How to use PAX for backup

How to use PAX for making backup

I will now like to tell you about PAX. I found in PAX a super commandline program for making backups. It takes a blink of the eye.
Before I turn off the machine for the day, I run backup scripts, for backing up the projects I have been working at during the day.
To have a script for each project will really make it easier to remember to backup. Imagine having one for the website you currently work at, and the documents that you write on at the moment. Anything.


Use this line to download and install PAX

sudo apt-get install pax

There is full coverage of how to use the command if you look in the man page for PAX. Like so.

man pax

Here is the finished shell script that I use for a project.

cd /var/www/html/project
rm backup.pax
pax -wzf backup.pax .
cp backup.pax /home/you/backup/project/$(date +%F).pax


As you can see first we change directory into the project directory in our apaches htdocs directory. Here we start by removing the old backup. So that we don't back that up also. Now we let PAX make a package containing the whole directory content, including sub directories. When that is done we copy the backup package to another path, and change name of the .pax file into a package named todays date. (Like 2015-05-23.pax).
I believe that you can change and adapt this script in several ways. For an example add the hour to the package name, in case you may need to make more backups the same day. Also you can make it send the package to yourself as an attachment to an email, also from the same scripts. I have added the scripts to my contextmenu in the “Files” filemanager, using Nautilus-Actions Configuration Tool. You can delete the original backup package after copying it to the backup directory. But I don't – it is okay to keep it, as another backup, it will be deleted at next run anyway. The backup is not named the date until copied, that way it is easy to know what file to delete (rm) from the project directory (backup.pax).

To unpack the pax-file you can do like so:

cd /home/you/backup/project
pax -rzf 2015-05-23.pax

..but keep in mind to do it in a directory for the same purpose, if your backup contains more than a few files. Messy.

The options I use for writing and reading with PAX is;

-w Write files to the standard output in the specified archive format.
-f Specify archive as the pathname of the input or output archive
-z Use the gzip utility to compress (decompress) the archive
-r Read an archive file

Look out for the next posting. In that I will make even better use of PAX. We will execute the scripts on hourly schedule. Using Crontab.

Here are the options to use, making a CronJob:

10  8  *  *  1-5  path/to/script
 |__|__|__|___|___|__________________ Minuts
    |__|__|___|___|__________________ Hours
       |__|___|___|__________________ Day in month
          |___|___|__________________ Month
              |___|__________________ Weekday
                  |__________________ Script to execute




 HTML

<HTML><BODY> 


</BODY></HTML>

 PHP

<?php


?>
Icons made by Freepik from www.flaticon.com This page will show you how you can use PAX making backup. Also see the page about making a ConJob
08:46:27