- s324114: FedericoMorro
- s319526: RedonKarakaci
- s323221: RedbHarry
- s303280: manarrre
To install the program download the builded zipped folder from ./Builds/<OS>, move it in the intended installation folder and extract the content (in Linux: tar -xvzf emergency-backup_Linux.tar.gz .). It is also possible to build the project from the repository as specified below (recommended for Linux due to dependencies). Afterwards, run main_emergency-backup.exe as administrator in Windows or main_emergency-backup NOT as sudo in Linux (sudo password will be asked by the installer).
After the installation, the program will be running in background, the GUI will open, and it will create:
settings.json: file with configurations, which can be modified via GUI or by handcpu_log.csv: log of main CPU usage (-1 signals program startup)
Furthermore, the program will be set to be launched at every system startup, the GUI will be listed in the application list for both OSes, and for Windows, it will be accessible via a desktop link, whereas in Linux, it will be accessible via terminal by typing the command emergency-backup.
To disable startup launch, kill running application, remove settings.json and links created:
- Windows: run
disable.batas administrator - Linux: run the command
main_emergency-backupwith--uninstallas argument NOT as sudo (the sudo password will be asked by the program)
Other files removal is up to the user.
The project can be built with windows_build.bat or linux_build.sh, given the project repository and cargo and npm installed (other than the Linux required dependencies listed at the end). The builded project will contain:
main_emergency-backup(.exe): main executableemergency-backup(.exe): GUI executablecat_ext.json: configuration file, which associates each file extension to a categoryicons: folder with app iconsvoice_audios: folder with audios (currently two languages supported: EN/IT)
Only on Windows:
disable.bat: disable script
By changing the settings, using the GUI or directly editing the file settings.json in the installation folder, is possible to act on the following parameters:
- Language: select the language of the audios and of the windows (EN and IT supported)
- Sources: select the files/folders to back up, specifying for each source:
- which categories of extension include
- which extensions are required and which have to be excluded (regardless the categories specified)
- which relative paths have to be excluded
- Destination (optional): select the destination path, which can be an external drive or, for instance, a shared folder; if not set (recommended), the external drive with the most available space at backup time will be taken as default destination; moreover, if the drive's storage gets full, you will be prompted to insert a new drive
For the GUI refer to the guide embedded in the question mark in the up left corner, whereas for the settings.json simply refer to JSON formatting and to the sample.
NB: the mapping between categories and extensions are specified in cat_ext.json; the user may add or remove extensions from the categories.
NB: files without extension are identified by the string No_ext.
Moreover, there are some more advanced settings which are only available by editing the file settings.json:
- Minimal: if the flag is set, the backup will have minimal log information, resulting in lower CPU usage and, in some cases, in lower overall backup time
- Threadpool: if the flag is set, the backup will leverage a threadpool
- Screen info: the struct contains the detected information about the screen in pixel, having the up right corner as origin
NB: using a threadpool to perform copy operations may lead to performances increase, but may also be counterproductive. To discriminate which option is best, it is recommended to test both possibilities with the drive on which one would like to perform the backup (if only one source is specified, the backup will always be single thread). In most cases, it is advisable to use a single thread backup.
To activate the backup, move the mouse along the edges of the screen clockwise, starting from the top left corner, making a rectangle shape. An audio message will signal the detection of the pattern and a confirmation window will appear with a 20 seconds timer.
It is possible to confirm the backup by making another rectangle shape, but counter-clockwise, or to wait for the timeout to cancel it. Moreover, it is also possible to interact with the window to confirm or cancel the backup.
If no destination was specified nor no external drive is found, an audio will signal the problem, and the program will wait for an external drive: press Ctrl to confirm the insertion and resume, Esc to exit. The same holds if the destination's storage gets full.
The backup completion will be signalled by an audio message, which also communicates the backup outcome. Moreover, during the process, a progress and information window will appear.
The program will create a _Emergency_Backup_ folder in the destination drive containing one folder for each source named Source_<n>.
When the backup is complete, in case of minimal backup a minimal_backup_log.txt will be added to the root folder with only essential information. Otherwise the log in the root folder backup_log.txt will contain detailed information about the backup and a log for each source _backup_paths_log.json will be added with the outcome of each path processed.
If the first drive gets full, the second drive will contain the logs of the first drive (also a write on the first one is attempted) in _Emergency_Backup_prev_dest_log_ folder, and the files that were missing in the first one (with logs), i.e. the copy will resume at drive change, not restart.
If in any moment, the program crashes, an information window will pop with the crash cause and an audio will signal the program fail.
BackupGuiRust: contains the rust tauri project for the GUI to modify the settingsMain: contains the rust project which manages the emergency backup
audio_player/states_audio.rs: voice audios playerauto_launch/startup_launch.rs: enable/disable running the app at startup time, manage linksbackup_process: handles backupbackup.rs: main backup logic and wrappers of copy functionscopy_thread.rs: copy function which iterates on directories, and compute statisticsdestination.rs: handles destination searching and requestinglog.rs: print functions for loggingminimal.rs: faster copy function with less statisticsthreadpool.rs: threadpool to manage concurrent copies
cpu_logger: handles cpu usage logcpu_log.rs: logs cpu datacpu_time.rs: get cpu time (used also by backup)
pattern_detection: monitor mouse movements to detect procedure activation/confirmationpatt_detect_state.rs: manages state update logicspatt_detect.rs: manages mouse interrupts
usb_drive/usb.rs: read usb drives plugged inwindow_spawner/window.rs: spawn windows to warn/inform the usersettings.rs: manage app settings reading and writingmain.rs: main run logic, command line arguments handling
The main program runs a state machine which waits for the pattern to be drawn by the user, then handles confirmation and if requested runs the backup process. The pattern detection and the cpu usage logging are done in different threads launched at main begin. Since the pattern detection uses an interrupt approach, which affects the main behaviour, the state is saved in a global variable protected by a mutex and paired with a condition variable to make the waiting phase not busy.
The enabling of the startup autolaunch is automatically done at the first program run (successive runs will trigger an error window), whereas the disabling is managed through a different process, which is run by calling the main executable with a different command line argument.
In Windows the enabling corresponds to creating a startup task and adding the executable to the applications and desktop through a link.
In Linux, an autostart file is created which runs a wrapper bash script, and links to the PATH and in the applications (as desktop entry) are added; additionally, a sudo rule is created to be able to run the program without requesting user password.
The backup is handled through a different process which is launched when requested by the main, by calling the executable with a proper command line argument.
The backup process first handles the destination searching as specified above. The drives are searched by looking at the computer USB-bus and the keyboard interactions are captured via interrupts and a global state variable as the one used for pattern detection.
Then, a vector of input structs to be passed to the copy function is created, which will iterate over the subfolder copying file, creating folders and computing statistics according to settings and, in turn, will return an output struct. The filters imposed by settings and the statistics gathering are handled through hash maps or hash sets.
There is a minimal and a complete version of the copy function: the main difference is the logging of the outcome for each path processed, which requires cpu time due to the need of a big storage vector. Furthermore, the copy is performed leveraging a threadpool or sequentially, depending on user settings and on number of sources.
If the drive gets full during the copy, the program asks for another drive, and resumes the copy from where it stopped, by modifying the input vector. At the end of the backup, the log files are printed.
If the standard pattern detection for activating the backup procedure does not work in Linux with Wayland, it is possible to press Ctrl + CapsLock to go to the confirmation phase. This possibility is only available if the program is built with wayland feature activated. This workaround was necessary as there is no established method for detecting the global mouse position in Wayland, due to the safety imposed by the protocol.
src: javascript and css GUI componentssrc-tauri: rust settings file update logic
For further details, refer to the README contained inside BackupGuiRust.
pattern_detectionlibxtst-dev libudev-dev libinput-dev libxdo-dev libxkbcommon-dev xorg-dev
audio_playerlibs2dl-dev
settingslibxcb1 libxrandr2
GUIlibwebkit2gtk-4.0-dev build-essential curl wget file libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev