Pi is a third party tool contributed by a few great guys (also responsible for the TRK menu) who wish to remain anonymous. Below is the (elaborate) manpage.
pi - automated backup wrapper script originally for Partition Image
pi -c -i [CONFIG FILE] -a -k [NUMBER OF COPIES] -d
The pi script was designed for:
make possible a fully automated backup system.
facilitate the use of partimage.
Type pi then <RETURN> to launch interactive mode.
- -c :
- search a pi.cfg configuration file and loads it if found. If this file contains the parameter AUTO=1, the backup will run automatically.
- -a :
- Starts the backup automatically (same as AUTO=1 in pi.cfg)
- -k # :
- This option (keep) sets the number of copies of the image to be kept. See details in Section Old backups below
- -d :
- debug mode. The backup will not be actually launched and the command that would have launched partimage is only displayed on the screen
- Trick :
- If you execute pi with -c -d, you will see which partition(s) and destination are selected from the found pi.cfg file.
- pi.cfg :
- pi can use a configuration file. This file is not needed in interactive mode. This file has two purposes :
- Add menu entries
- pi automatically creates the list of your local drives. If you want to backup to a network drive, you must add it in pi.cfg
- Automatic mode
- All selections can be set in pi.cfg and then pi can run without any user intervention A pi.cfg file corresponding to your backup is created in the destination directory each time a backup is successful.
- Add menu entries
- partition_info.txt :
- Each time you make a backup, a file named partition_info.txt is created in the destination directory. This file contains information on your partitions (all partitions of all local drives, even USB disks or USB keys). This may be useful in case you have to repartition your disk after a crash.
WARNING : partimage is unable to restore an image on a partition smaller than the original partition. See the documentation of partimage for details. Therefore it is very important to know the size of the partition that an image contains. unpi, the complementary script of pi, will give this information but you can also find it in partition_info.txt.
pi mounts the backup unit you have chosen on /sysbackup
Well, you have make an image not only for the fun, you may want to restore it one day. You can use partimage or unpi the little brother of pi which will help you for restore in the same way that pi helps you for backup.
If the pi script is run with the -c option, and there is a pi.cfg file in the root directory of any disk in the machine, or in /trk/trk3/pi or in /etc/pi and all options necessary are set, then pi is launched automatically, using the pi.cfg parameters. If pi.cfg is not found or uncomplete, pi exits immediatly.
- If the pi script is run without the -c option then pi is launched interactively and three successive menus ask the user to select:
- The unit or units to save.
- The destination disk that store the backup (local drive or network)
- The destination disk list may be customized using MENU_UNIT, MENU_LOGIN and MENU_PASS in pi.cfg file.
- The destination directory
- a) The partitions to save
- Here you can select a partition in the list of partitions found by the system, or select "information on partitions" for more information on your partitions, or select "select several partitionsâ€. In this case you must type the names of the partitions to save as they appear in the list, separated by spaces. For example:
- b) The destination drive (the one on which the backup will be saved).
- A list presents successively the units defined in pi.cfg and the units that the system finds on local disks. After selecting the unit, the script will attempt to mount the disk. If it fails, an error message is sent and the script stops. Possible causes include, among others:
- 1. You have chosen an NTFS partition and Windows has been put in hibernate state on the disk. In this case, NTFS partitions are not closed and they cannot be mounted rread/write, you can only read. It is possible to make a backup of such partition, but you cannot use it as the destination unit. To avoid this error, completely shut down Windows before starting TRK Autobackup. Since TRK revision 3.4 : hibernated partition cannot be written, but the state of other not closed partitions is normally solved by ntfs-3g which is able to successfully mount them for writing. However it is always better to properly shut down Windows before making a backup.
- 2. The system also put in the list extended partitions, which can disturb. An extended partition is a mere container and cannot receive files. For information on how your partitions are made, use the "information about partitions" option of the main menu.
- 3. You have selected a network drive and the network connection is not good, or your LOGIN and PASSWORD parameters are incorrect.
- c) The destination directory
- In the destination device previously defined, the script can either use the existing directories that are presented here, or a new directory: in this case select the last option and type a directory name without spaces in its name. We are in Linux which does not accept spaces in the names of directories and files.
Then the script will present you a summary of your choices that you can confirm or reject by y(es). or n(o). In the last case the script closes. Finally before running the backup a last message information is presented. You can again interrupt the process by pressing any key other than SPACE or ENTER, or type on ENTER to immediately start the backup, or let the script look after himself. After 15 seconds, if you do nothing, it will launch the backup.
To enable automatic operation, you must file a pi.cfg in the root directory of a partition of the machine (all mountable partitions are scanned) or in /trk/trk3/pi (for TRK users) or in /etc/pi and the script must be launched with option -c. The first file found will be used.
If the file is found, the parameters are loaded and the backup is started. This backup will be excuted without any user intervention if all necessary parameters are set in the file and if AUTO has been set to 1. but there are two confirmation messages which are displayed for 10 or 15 seconds, and during this time you may stop the process before the backup starts. If AUTO=0, then a confirmation is requested from the user. If you add the command pi -c to your trklocscript file in the trk3 directory, then you can have a CD or USB key which will backup the partitions you have defined without any intervention of the operator : just boot on the CD or the USB key, and you are done. This is handy if you want users who don't know anything about computers to be able to save their system disk from time to time.
To setup automatic mode, the recommended steps are :
- Use pi in normal interactive mode to make your first backup.
- Once you are satisfied and anything works as you want, locate the the pi.cfg file which has been created in your successful backup directory
- Copy this file in the root of your first drive (any other drive can be chosen, but it is more easy to use the first one, generally sda1 or c:)
- You can edit this file in Linux or Windows if you want to change something, Windows end of lines are supported. Complete description of this file format is explained below in the section CONFIGURATION FILE.
- At this point, if you run pi -c your backup will start automatically. You will have two occasions offered to you to stop it.
If you add the command pi -c in the trklocscript file in the trk3 directory of your TRK disk, then it is possible to start a backup by just booting on this disk, without any further intervention. Complementary details are found in the FAQ. $$$
Pi creates three files (or file set) in the destination directory :
- The partimage files with extension .000, .001 .002 etc.
- a pi.cfg file with the configuration you have just used and which can be used for automatic process.
- a partition-info.txt file, which contains the details of your hard disks configuration. It may be very useful in case you must reformat your disk
During the backup, partimage shows a screen that displays the progress of the operation. Despite the message that is displayed at the bottom of the screen, it is unfortunately not possible to interrupt a backup because the * option does not work. This is a bug in partimage. If you want to stop anyway, you can do a ctrl+alt+del. You will just need to think about delete the created files.
The script handles the number of copies of your partitions you want to keep. The default is 2 (the copy you just made, and one older). This value can be changed with the option -k. 4 will mean : the image just made + 3 older copies (total : 4 copies). Examples :
- -k1 : One image : all older images are deleted
-k2 : The last image + 1 older image (default)
-k3 : The last image + 2 older images
-kn : The last image + (n-1) older images
-k0 : Special mode (see below : IN CASE OF LOW SPACE IN THE DESTINATION) The digit does not mean the number of older copies but the total number : -k2 will not keep two older copies but one.
The behaviour is the following :
- a) the current backup is performed into temporary files.
- b) these temporary backup files are renamed with their final backup filenames, like 20YY-MM-DD-X-hda1.000
- c) a sub-directory is created with the following name: 20YY-MM-DD-saved_partition, for example: 2010-06-22-hda2 and the current backup files of this partition are transferred under this sub-directory.
- d) depending of the number specified with the k option, old backups are deleted: for example, if user has specified pi -c -k 4 and there are already 3 existing 20YY-MM-DD-saved_partition sub-directories, the oldest one will be automatically removed once the current backup will have successfully completed.
CONFIGURATION FILE (pi.cfg)
CAUTION: The name of the configuration file is pi.cfg or PI.CFG or Pi.cfg. ALL OTHER SPELLINGS WILL BE IGNORED.
Spaces are not allowed in file names or directory (replace them by _ or -)
When you have completed a backup, the destination directory contains a pi.cfg file corresponding to the options you had choosed. Here is a possible example :
# No space before and after the = sign
# The names are case-sensitive
# No backslashs: \, only slashs/
# MENU_UNIT[x]=//192.168.1.4/sysbackup specify a network disc to be displayed in the interactive choice of BACKUPDRIVE
# MENU_LOGIN[x]=//192.168.1.4/sysbackup specify login of the network disc[x] displayed in the interactive choice of BACKUPDRIVE
# MENU_PASS[x]=//192.168.1.4/sysbackup specify password of a network disc[x] displayed in the interactive choice of BACKUPDRIVE
# x index start at number 1. Several network discs may be specified using different indexes.
# Destination automatic backup unit. It may be a network drive, for example:
# BACKUPDRIVE =//192.168.1.4/sysbackup
# In this case the parameters LOGIN and PASSWORD are required
# Or a local unit such as BACKUPDRIVE=/sdb1
# Backup directory in automatic mode
# Beginning of backup files' names;
# pi will generate 20YY-MM-DD-X- prefix in the filename of the unit to backup
# (X=A for automatic and I for Interactive) and partimage will add the extension 000, 001 and so on.
# Example : in Automatic mode, the resulting file should be :
# Example : in Intercative mode, the resulting file should be :
# Partitions to backup in automatic mode
# If there are multiple partitions, separate them by spaces,
# and put it between quotation marks
# Example PARTITION="sda1 sda5"
# If AUTO=1 and a pi.cfg configuration file was found,
# the backup is done without any user intervention
Always use the forward slash and not the backslash: we are in Linux and not in Windows. Long before Microsoft existed, the backslash was an escape character on Unix. Only Microsoft's commitment to be "like no other" has led to ignore this meaning and use the backslash in directories' path. Linux meets Unix standards. There are never spaces before or after the equal sign under penalty of non-functioning of the script. The parameters' names are always written in uppercase.
You may indicate a network drive, and in this case it will be also mandatory to specify LOGIN and PASSWORD. The format will be: //xxx.xxx.xxx.xxx/shared_directory_name. This can also be a local drive and in this case the format will be, for instance: /dev/sda1. It is prudent to use the complete device names returned by info on partitions. /sda1 should work too, but /dev/sda1 is safer.
This is the destination directory to be used (and possibly created) in the unit selected by BACKUPDRIVE. It is possible to select a subdirectory, but in this case it is mandatory that the directory already exists. Example:
<FILE> - <partition> .000 DEST=backup/system/unite_c
If the saved partitions are hda1 and hda5, the following files are created (X=A or I):
This parameter contains the names of the partitions to backup. If there is one partition, you can simply specify it as follows:
If there are multiple partitions, they must be separated by spaces and put between quotation marks:
It is allowed to have spaces between quotation marks but it is prohibited outside. PARTITION= "hda1 hda5" will not work because you should never have a space before and after the = sign
Note the different syntax from BACKUPDRIVE. There's no slash or /dev/.
AUTO=1 enables automatic backup and a delay is placed on the confirmation messages. It is possible to interrupt the process by pressing any key other than SPACE or ENTER during the period. After the delay and without user intervention, backup is started.
This parameter has the same meaning as the parameter -k (see the section "Old backups" above). The default value is 2.
IN CASE OF LOW SPACE ON THE DESTINATION
using -k0 option
In the normal process described above, there is a moment where you have two images of your partition : one that is currently on temporary files and one which is in the normal directory. If you do not have enough space on your disk for this, you can use the -k option with a value of 1 or 0
- If you have enough disc space for two copies of the image but want to keep only the last, this parameter will cause the following behaviour:
a) creation of the new image in temporary files
b) if the image was successful, the old image is erased
c) the new image files are renamed.
If the image had failed, temporary files remain on the disk. They will be overwritten by the new image when you will try again to make one. You can also delete them yourself.
- If you have just the place for an image, this parameter will give the following behavior:
- a) erase the existing image
b) creation of the new image
Warning: this mode is not secure because if the creation of the new image fails, the old image has already been erased.
- Q: How can I make a fully automatic image system for my hard disk ?
- A: The first step is to setup a pi.cfg file which will do what you want : save your system partition or all your partitions to a given destination.
Once this is done and you can run pi -c and get the result you want, the hardest part is done. See above for all informations on this step.
Now you have to run this automatically when TRK starts. This is easy :
- Add a file with the name "trklocscript" in the trk3 directory of your TRK USB key or your TRK CD.
- In this file add this line :
You are done.
- Q: My computer does not boot on an USB device and I must boot on CD. I cannot copy a file to a CD.
- A: When you burn your TRK CD, be careful to let the session open. This can be configured if you are using CdBurnerXP on windows. Some versions of Nero automatically close the session and don't let you add anything.
- Open your CD in a CD burner program
- Choose the option to continue the CD
- add trklocscript as described above in the trk3 directory
- burn your cd
- Run it. You are done.
- Q: And what will happen with this CD/USB key ?
- A: Just boot a computer which has a valid pi.cfg file in the root directory of one of its disks, and the backup defined in that pi.cfg file will be performed. If you had set AUTO=1, just sit back and relax the job will be done automatically. If you are suspicious and want to know what happens before it is performed, then set AUTO=0 and you will have a confirmation screen.
- Q: I am lazy and I want a simpler solution
- A: OK. You must first create a TRK USB key with trk2usb.
Add trklocsript to the trk3 directory of this key
Ask a friend who has a computer which starts on USB key to start his computer on your TRK USB key and to run the command :
N.B. He must first change to a directory with at least 150 Mo of free space
Then ask him to give you the iso file created.
Burn it and you are done.
- Q: This is not so simple
- A: At first, yes. But once you have your USB key it is very easy to modify it, and then ask your friend to create the new iso. If he is patient enough, it is a good solution.
- Q: I don't want to run always pi on startup. Is it possible to have this feature enabled on a computer and not on another ?
- A: Yes, it is easy : with the pi -c command in the trklocscript file, if a computer has a pi.cfg file, pi will run when TRK starts. If a computer does not have this file, then pi will appear for 3 seconds, then disappear and the TRK menu will be shown.
Frank Michel (for the menus), Gaston and Averell