Simple backup script

To save your files periodically, it is best to use an archiving software with you own list of directories to save, to avoid to type the same commands again and again.

SEB (Simple and Efficient Backup) is a script written in Scriptol/PHP that automates frequent backups of your data.

How the script works

Essentially, here what to add to the archiver:

  1. An array containing the list of files or directories to backup regularly.
  2. The name of the archive, built automatically based on the date and time.
  3. A command with the options of 7-Zip (or PKZip).

The program then includes the following code ...

A table containing a list of files or directories.

array saving = [
....filenames separated by a comma...
]

PKZip Only: For a directory, you add after the slash an asterisk. Example:

w:/scriptol.com/     // for 7-zip
but
w:/scriptol.com/*     // for pkzip

Automatic creation of the archive name with in the order: year, month, day, hour, minute.
This file name will be concatenated with the name of the drive unit and possibly the destination directory, and passed on the command line.

text newdir = "backup-" + Date("Y-M-d-H-i") 

Building the command to the archiver.

 text command = "7z a -tzip $target "
for text t in saving
command + t + " "
/for

Run the command:

exec(command)  

The structure of directories and files will be stored in the archive.

Using the program

Extract the contents of the archive to the root of the disk. The script will be accessible from the command line in the directory /seb/.

Place 7z.exe 7z.dll in a directory taken into account by the PATH variable, that allows to run this programs from any directory.

Yu must first edit the script code, either in the source seb.sol or in php seb.php, in order to provide a list of files and directories to save.

To do this, modify the contents of the saving array as described above.

array saving = [ your comma-separated list of dirs ]

Choose your time zone, and assign it to the following function:

date_default_timezone_set("US/Central") 

The list of time zones is in the PHP manual. Replace "US/Central" by that of your city.

Then you can run the script. Give at the command line the destination drive or directory.

Example in Scriptol:

solp seb d:

Example in PHP:

php seb.php d:/temp/

If /temp does not exist on the drive, it will be created.

Restoring from the backup

One day perhaps you accidentally or because of a virus, lose all or part of your data.

You can then rebuild the directory structure with all the files, by the command:

7z e archivename.zip   

If you just want to recover a file or a directory, you can use an archive manager to select the files, and the destination, through a GUI.

With Windows 7, it is possible to open a zip archive as a folder, and with the mouse to move a directory or file to a directory of the file system.
By the way, you can also create a "compressed folder", actually a zip archive, and move files and directories into.

Download the archive of SEB

In the second part, we will see how to create an incremental backup script by updating a same file with an archiver.