User Tools

Site Tools


11.11 Backup of projects

The author has been working for many years on the online version of the Gambas book at 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:


Figure Backup tool in Mint 17.3


  • You can exclude selected folders and files from the backup in a further step.
  • Before starting the backup, you should check the settings!
  • The archive name follows the syntax: year-month-day-id-backup.tar.gz, if you select a tar.gz archive for the output:


Figure 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 ( is pleasantly short:

[1] #!/bin/sh
[2] #
[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


  • Check if the program 'rsync' is installed. If necessary, make up the installation.
  • Before you start seriously, please read the details of the console program rsync with 'man rsync' and 'rsync -h' carefully.
  • Many examples are shown on the page
  • Use the USB stick only for backups.
  • The script must be executable.
  • For first tests you should start with a test directory with 2 directories to be backed up and some files.
  • The first tests should be done several times with the option –dry-run (short form -n) until everything fits - so you don't experience any nasty surprises. Keep in mind that you are working with root privileges and that directories and files are extensively deleted, moved and copied.
$ 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/

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:


Figure 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


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.
/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 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.

  • In the download area you will find a bash script with the above source code. For your backup, you must change the source code in lines 10 and 29 when saving to a USB stick.

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:


Figure 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
     Message.Error(("Wrong sudo password!") & GB.LF & ("Please try again."), "OK")
     ErrorList &= sErr & gb.Lf

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:

  • The program' gb.rsync' checks whether the required console program 'rsync' is installed on your computer. If not, you will receive a note and instructions on how to install it.
  • You will normally find attached media such as USB sticks in the directory '/medien/user'.
  • If the program reports errors of the type “Operation not permitted” during a synchronization, perform the same backup again under root privileges → CheckBox 'As Root'.
  • The function of the option '--delete' is already explained in variant 3 described above, but a backup directory with the name '/Backup' is created in the program 'gb.rsync' in the target directory.
  • The '--slow' option compresses the transferred data when transferring over slow connections.

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.


The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k11/k11.11/start.txt · Last modified: 23.09.2023 by honsek

Page Tools