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.
At irregular intervals, the Gambas projects are burned to DVD and stored well.
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 11.11.2.1: Backup tool in Mint 17.3
Hints:
Figure 11.11.2.2: Archive file
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:
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
Option - Parameter | Description |
---|---|
-a | List of tested options (? Manual) |
-b | Backups are created. |
–dry-run (abbreviation: -n) | A synchronization is simulated. There is a dry test run which does not really synchronize anything! |
–progress | The progress during synchronization is displayed. |
–delete | Files that no longer exist in the source are also deleted in the target. |
–backup-dir= | ~ |
/media/$USER/$STICK/GB3Backup | What 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/GB3Projects | Target 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.
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 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!
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.
Der Autor arbeitet seit vielen Jahren unter http://www.gambas-buch.de an der Online-Version des Gambas-Buches. Daher ist die Anzahl der bearbeiteten Gambas-Projekte in den über 30 Buch-Kapiteln sehr groß. Diese Projekte werden deshalb von Anfang an regelmäßig auf mehrere mobile Datenträger gesichert.
In unregelmäßigen Abständen werden die Gambas-Projekte auf DVD gebrannt und gut verwahrt.
Für die regelmäßige Sicherung der Gambas-Projekte wird das Programm 'Datensicherungswerkzeug' (→ Mint 17.3) eingesetzt, das einfach zu bedienen ist und mit den erprobten Einstellungen ein Archiv auf dem Ziel-Datenträger speichert:
Abbildung 11.11.2.1: Datensicherungswerkzeug in Mint 17.3
Hinweise:
Abbildung 11.11.2.2: Archiv-Datei
Favorit bei der Sicherung der Gambas-Projekte ist immer noch ein kleines Shell-Skript für das Programm 'rsync'. Das Skript synchronisiert den Ordner mit allen Gambas-Projekten gegen den (gleichnamigen) Ordner auf einem mobilen Datenträger. Alle Änderungen im Projekt-Ordner werden in einem Backup-Ordner gespeichert, so dass zum Beispiel auch gelöschte Projekte dort mit gesichert werden. Es ist von Vorteil, dass man in der Ordner-Struktur der Sicherung jederzeit nach interessierenden Projekten suchen kann. Der Bash-Quelltext für das Skript (projekte2usbstick.sh) ist erfreulich kurz:
[1] #!/bin/sh [2] # [3] # FARB-WERTE: [4] RO="\033[31m" # Schriftfarbe rot [5] FR="\033[1m\033[31m" # [6] FG="\033[1m\033[42m\033[37m" # Schriftfarbe fett + weiß + grüner Hintergrund [7] NO="\033[0m" # Schriftfarbe normal [8] # [9] echo [10] STICK="16_GB_P" # Geräte-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}Der USB-Stick $STICK muss eingehängt sein!"; [16] echo "Das Sicherungsprogramm wird deshalb beendet!${NO}"; [17] echo [18] echo "Beenden mit ENTER!"; [19] read a [20] exit 1; [21] else [22] echo [23] echo "${FG}Sicherung Gambas-Projekte auf USB-Stick $STICK mit ENTER starten ...${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}Ende der Sicherung auf $STICK.${NO}" [35] echo [36] echo "${FR}Der USB-Stick $STICK wird anschließend ausgehängt!${NO}" [37] echo "${FR}Abschluss mit ENTER!${NO}" [38] read b [39] fi [40] echo [41] echo "${FG}Unbedingt warten, bis der USB-Stick $STICK ausgehangen worden ist!${NO}"; [42] echo [43] umount /media/$USER/$STICK
Hinweise:
$ sudo rsync -ab --dry-run --progress --delete --backup-dir=/media/$USER/$STICK/GB3Backup $HOME/GB3Projekte/ /media/$USER/$STICK/GB3Projekte
Es folgt die (stark gekürzte) Ausgabe für einen Trocken-Synchronisationsdurchlauf :
Sicherung Gambas-Projekte auf USB-Stick 16_GB_P mit ENTER starten ... _____________________________________________________________________ [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) _____________________________________________________________________ Ende der Sicherung auf 16_GB_P. Der USB-Stick 16_GB_P wird anschließend ausgehängt! Abschluss mit ENTER! Unbedingt warten, bis der USB-Stick 16_GB_P ausgehangen worden ist!
Wenn der USB-Stick für die Sicherung nicht eingehängt ist, so wird das erkannt und angezeigt sowie das Skript beendet:
Abbildung 11.11.3.1: Fehleranzeige
Wenn alle Tests ohne Fehler durchgeführt worden sind, dann können Sie Ihre Gambas-Projekte sichern. Nach einem Synchronisationsdurchlauf sind die ausgewählten Ordner auf der Festplatte (Quelle) auch 1:1 auf dem USB-Stick (Ziel). Veränderungen befinden sich im Backup-Ordner auf dem USB-Stick.
Diese Zeile* zur synchronen Sicherung eines Verzeichnisses – mit Backup – leistet die Hauptarbeit:
$ sudo rsync -ab --progress --delete --backup-dir=/media/$USER/$STICK/GB3Backup $HOME/GB3Projekte/ /media/$USER/$STICK/GB3Projekte
Option - Parameter | Beschreibung |
---|---|
-a | Liste erprobter Optionen (→ Manual) |
-b | Backups werden erstellt. |
–dry-run (Kurzform: -n) | Es wird eine Synchronisation simuliert. Es erfolgt ein Trocken-Testlauf, der nichts wirklich synchronisiert! |
–progress | Der Fortschritt während des Synchronisierens wird angezeigt. |
–delete | Dateien, die in der Quelle nicht mehr existieren, werden auch im Ziel gelöscht. |
–backup-dir= | |
/media/$USER/$STICK/GB3Backup | Was nicht synchronisiert werden kann, weil verschoben oder im Original gelöscht, wird im Backup-Verzeichnis aufgehoben. |
$HOME/GB3Projekte/ | Quellverzeichnis im Home-Verzeichnis auf Festplatte. Achten Sie auf das Slash-Zeichen am Ende! |
/media/$USER/$STICK/GB3Projekte | Zielverzeichnis auf dem USB-Stick im Wurzelverzeichnis. |
Tabelle 11.11.3.1 : Übersicht zu Optionen und Parametern in der Kommando-Zeile*
Sie können jederzeit weitere Zeilen in den Skript-Quelltext einfügen, wenn weitere Verzeichnisse mit ihren Unterverzeichnissen und den darin enthaltenen Dateien synchronisiert gesichert werden sollen.
Diese Variante der Datensicherung wurde in Form eines Gambas-Frontends für das Konsolen-Programm 'rsync' realisiert. Diese Anwendung erlaubt das Anlegen und Editieren einer Jobliste für das Synchronisieren von Verzeichnissen oder einzelner Dateien.
Die optionale Anwendung von Root-Rechten bei Shell-Hintergrundprozesse wird durch die Option '-S' des 'sudo'-Kommandos erreicht, die eine Umleitung der Passwortabfrage in die Error-Routine des Prozesses bewirkt, wo das Root-Passwort an den Prozess übergeben werden kann:
Abbildung 11.11.4.1: Gambas-Frontend 'gb.rsync'
Beispiel für den Start eines Shell-Prozesses mit Root-Rechten:
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"
Die Übergabe und Überprüfung des Root-Passwortes erfolgt in der Error-Ereignis-Routine des Shell-Prozesses:
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
Da es bei parallel ablaufenden 'rsync'-Hintergrundprozessen zu unberechenbaren Abläufen kommen kann, sorgt das Programm für sequenzielle Shell-Aufrufe. Nur so ist gewährleistet, dass der vollständige Abschluss aller Synchronisierungsaufgaben zuverlässig erkannt wird und auftretende Fehlermeldungen der Reihe nach erfasst werden.
Als Besonderheit ist die Anwendung des ColumnView-Steuerelements zu erwähnen, dem (Pseudo-) Checkboxen in Form von Grafiken hinzu gefügt wurden. Eine Beschreibung der Eigenschaften, Methoden und Ereignisse des Steuerelements ColumnView finden Sie im Kapitel → 17.5 ColumnView.
Hinweise für die Nutzung des Programms:
Beachten Sie: Die Nutzung des Programms gb.rsync erfolgt auf eigene Gefahr!
Wenn Ihnen von einem Anbieter Cloud-Speicher in hinreichender Größe zur Verfügung gestellt wird, dann sollten Sie erwägen, ihre Gambas-Projekte (auch) dort verschlüsselt zu speichern. Das hätte den Vorteil, dass Ihre Daten – im Gegensatz zu den anderen Varianten – an einem unabhängigen Ort gespeichert sind. Bisher wurde diese Variante vom Autor noch nicht umgesetzt – wird aber erwogen.