Table of Contents

11.11 Backup of projects

The author has been working for many years on the online version of the Gambas book at http://www.gambas-buch.de Therefore, the number of Gambas projects in the more than 30 book chapters is very large. For this reason, these projects are regularly backed up to several mobile data carriers right from the start.

11.11.1 Variant 1

At irregular intervals, the Gambas projects are burned to DVD and stored well.

11.11.2 Variant 2

For the regular backup of Gambas projects, the program' Data Backup Tool' (→ Mint 17.3) is used, which is easy to use and stores an archive on the target disk with the tried and tested settings:

B1

Figure 11.11.2.1: Backup tool in Mint 17.3

Hints:

B2

Figure 11.11.2.2: Archive file

11.11.3 Variant 3

Favourite for saving the Gambas projects is still a small shell script for the program' rsync'. The script synchronizes the folder with all Gambas projects against the (same named) folder on a mobile disk. All changes in the project folder are saved in a backup folder, so that deleted projects are also saved there, for example. It is an advantage that you can search for interesting projects in the folder structure of the backup at any time. The base source code for the script (projects2usbstick.sh) is pleasantly short:

[1] #!/bin/sh
[2] #
[3] # FARB-WERTE:
[4] RO="\033[31m"                 # Font color red
[5] FR="\033[1m\033[31m"          #
[6] FG="\033[1m\033[42m\033[37m"  # font color bold + white + green background
[7] NO="\033[0m"                  # font color normal
[8] #
[9] echo
[10] STICK="16_GB_P" # Device label USB stick (16GB)
[11] #
[12] df -k | grep /media/$USER/$STICK 1>/dev/null 2>/dev/null
[13] if [ $? -gt 0 ];
[14] then
[15]   echo "${RO}The USB stick $STICK must be mounted!";
[16]   echo "The backup program is therefore terminated!${NO}";
[17]   echo
[18]   echo "Exit with ENTER!";
[19]   read a
[20]   exit 1;
[21] else
[22] echo
[23] echo "${FG}Start backup of the Gambas projects on USB stick $STICK with ENTER...${NO}"
[24] echo "__________________________________________________________________________";
[25] echo
[26] read a
[27] # Muster:
[28] # sudo rsync -ab --progress --delete --backup-dir=BACKUP-DIR SOURCE-DIR/ TARGET-DIR 
[29] sudo rsync -ab --progress --delete --backup-dir=/media/$USER/$STICK/GB3Backup $HOME/GB3Projekte/ /media/$USER/$STICK/GB3Projekte  
[30] #
[31] echo
[32] echo "__________________________________________________________________________";
[33] echo 
[34] echo "${FR}End of backup to $STICK.${NO}"
[35] echo
[36] echo "${FR}The $STICK USB stick is then displayed!${NO}"
[37] echo "${FR}Finish with ENTER!${NO}"
[38] read b
[39] fi
[40] echo
[41] echo "${FG}It is essential to wait until the $STICK USB stick has been hang out!${NO}";
[42] echo 
[43] umount /media/$USER/$STICK

Hints:

$ sudo rsync -ab --dry-run --progress --delete --backup-dir=/media/$USER/$STICK/GB3Backup $HOME/GB3Projekte/ /media/$USER/$STICK/GB3Projekte

This is followed by the (strongly shortened) output for a dry synchronization run:

Start backup of Gambas projects on USB stick 16_GB_P with ENTER..
_____________________________________________________________________

[sudo] password for hans: 

sending incremental file list
created directory /media/hans/16_GB_P/GB3Projekte
Created backup_dir /media/hans/16_GB_P/GB3Backup/
./
CSV2XML_WRITER/
CSV2XML_WRITER/.directory
CSV2XML_WRITER/.gitignore
...
CSV2XML_WRITER/Symbols/form_icon.png
CSV2XML_WRITER/Symbols/projekt_icon.png
DATA2XML_WRITER/
DATA2XML_WRITER/.directory
...
DBDATA2XML_WRITER/Symbols/report32.png

sent 3,478 bytes  received 476 bytes  7,908.00 bytes/sec
total size is 424,536  speedup is 107.37 (DRY RUN)
_____________________________________________________________________

End of backup to 16_GB_P.
The USB stick 16_GB_P will then be unhooked!
Finish with ENTER!

It is essential to wait until the USB stick 16_GB_P has hang off!

If the USB stick for the backup is not attached, this is detected and displayed and the script is terminated:

B3

Figure 11.11.3.1: Error display

If all tests have been performed without errors, you can back up your Gambas projects and after a synchronization run, the selected folders on the hard disk (source) are also 1:1 on the USB stick (target). Changes are located in the backup folder on the USB stick.

This line* for synchronous backup of a directory - with backup - does the main work:

$ sudo rsync -ab --progress --delete --backup-dir=/media/$USER/$STICK/GB3Backup $HOME/GB3Projekte/ /media/$USER/$STICK/GB3Projekte

tablelayout

Option - ParameterDescription
-aList of tested options (? Manual)
-bBackups are created.
–dry-run (abbreviation: -n)A synchronization is simulated. There is a dry test run which does not really synchronize anything!
–progressThe progress during synchronization is displayed.
–deleteFiles that no longer exist in the source are also deleted in the target.
–backup-dir=~
/media/$USER/$STICK/GB3BackupWhat cannot be synchronized because moved or deleted in the original is removed from the backup directory.
$HOME/GB3Projects/Source directory in the home directory on hard disk. Pay attention to the slash sign at the end!
/media/$USER/$STICK/GB3ProjectsTarget directory on the USB stick in the root directory.

Table 11.11.3.1: Overview of options and parameters in the command line*

You can insert additional lines into the script source code at any time if you want to synchronize additional directories with their subdirectories and the files they contain.

11.11.4 Variant 4

The optional use of root privileges in shell background processes is achieved through the' -S' option of the' sudo' command, which redirects the password request to the error routine of the process, where the root password can be passed to the process:

Synchronisataion

Figure 11.11.4.1: Gambas front end' gb. rsync'.

Example of starting a shell process with root privileges:

SCommand = "LC_ALL=en_GB.utf8 sudo -S rsync -ab --progress --delete /home/user/Documents /media/user/STICK"
 
' Start rsync process with shell command
hShellProcess = Shell sCommand For Read Write As "rsyncShellProcess"

The root password is passed and checked in the error event routine of the shell process:

Public Sub rsyncShellProcess_Error(sErr As String)
 
  Dim PW As String
 
  If sErr Like "*password*" Then
     PW = TextBoxPW.Text
     Print #hShellProcess, PW & gb.LF
     PW = ""
  Else If sErr Like "*try again*" Then
     If hShellProcess
        hShellProcess.Close()
        hShellProcess.Kill()
     Endif
     Message.Error(("Wrong sudo password!") & GB.LF & ("Please try again."), "OK")
   Else
     ErrorList &= sErr & gb.Lf
  Endif
End

Since parallel running' rsync' background processes can cause unpredictable processes, the program provides sequential shell calls. This is the only way to ensure that the complete completion of all synchronization tasks is reliably detected and error messages are recorded in sequence.

A special feature is the application of the ColumnView control to which (pseudo-) checkboxes in the form of graphics have been added. A description of the properties, methods and events of the ColumnView control element can be found in Chapter → 17.5 ColumnView.

Instructions for using the program:

Please note: The use of the program gb.rsync is at your own risk!

11.11.5 Variant 5

If you are being provided with sufficient cloud storage by a provider, you should consider storing your gambas projects there in encrypted form. This would have the advantage that your data - in contrast to the other variants - is stored in an independent location. Up to now, this variant has not yet been implemented by the author - but is being considered.

Download