backing_up_your_data
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
backing_up_your_data [2021/07/29 11:24] – atolstov | backing_up_your_data [2023/05/02 10:43] (current) – atolstov | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Backing up your data ====== | ====== Backing up your data ====== | ||
- | {{ :: | + | |
+ | |||
+ | {{ network: | ||
+ | \\ | ||
+ | \\ | ||
<WRAP center round important 80%> | <WRAP center round important 80%> | ||
- | Though you might use industrial storage solutions for the WebHMI, still __there is always a risk of loosing | + | Though you might use industrial storage solutions for the WebHMI, still __there is always a risk of losing |
- | *Just forget to make a copy of the project - this is most common case. Backup files are created on local WebHMI storage for your convinience, but it's up to you to save the latest valuable changes on your PC or other storage. | + | *Just forget to make a copy of the project - this is the most common case. Backup files are created on local WebHMI storage for your convenience, but it's up to you to save the latest valuable changes on your PC or other storage. |
- | *Occasionnally | + | *Occasionally |
*Flash drive wearing out | *Flash drive wearing out | ||
- | *Abrupt power off during critical file operation (which you can not control) - on virtual machine or WebHMI with failed backup battery | + | *Abrupt power off during critical file operation (which you can not control) - on a virtual machine or WebHMI with a failed backup battery |
- | *Filesystem/ | + | *Filesystem/ |
</ | </ | ||
+ | There is only one example of how to **avoid the consequences of data loss** considered here. Using shell script via crontab utility. | ||
- | There are a lot of way to **avoid the consequences of data loss**. | ||
- | Here is an example of how to setup your Linux machine to automatically save files from the ''/ | + | ===== Download all present logs once ===== |
+ | At the very start, it is a good idea to download all the data. | ||
- | <code bash> | + | <code bash backup-ALL.sh> |
#!/bin/bash | #!/bin/bash | ||
- | # Create a folder ~/WEBHMI/ | + | # Create a folder ~/webhmi-log-cron, with the /tmp sub-folder. |
- | LOG_DIR=" | + | HOST=192.168.1.1 |
- | cd $LOG_DIR | + | LOG_DIR=" |
- | # download | + | mkdir -p $LOG_DIR/tmp |
+ | cd $LOG_DIR/ | ||
+ | |||
+ | # Get all logs (including today, which is, however, obviously partial) | ||
+ | wget --user=admin --password=webhmi -nH --cut-dirs=1 " | ||
+ | |||
+ | # Archive to save storage space | ||
+ | gzip -f -v * | ||
+ | # Copy out of tmp .gz file and do not overwrite if destination filename already exists | ||
+ | cp -r --backup=t log-*.sqlite3.gz ../. | ||
+ | # Clear tmp folder | ||
+ | rm $LOG_DIR/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Crontab on Linux ===== | ||
+ | Here is an example of how to set up your Linux machine to automatically save files from the ''/ | ||
+ | <code bash backup.sh> | ||
+ | # | ||
+ | # Create a folder ~/ | ||
+ | HOST=192.168.1.1 | ||
+ | LOG_DIR=" | ||
+ | cd $LOG_DIR/tmp | ||
+ | # download yesterday' | ||
yesterday=$(date +" | yesterday=$(date +" | ||
+ | |||
+ | |||
+ | |||
+ | # because login and pass for the FTP connection are unencrypted you can | ||
+ | # restrict read/write access mode to the file with chmod command) | ||
+ | wget --user=admin --password=' | ||
+ | #archive to save storage space | ||
+ | gzip -f -v log-$yesterday.sqlite3 | ||
+ | # Copy out of tmp .gz file and do not overwrite if destination filename already exists | ||
+ | cp -r --backup=t log-$yesterday.sqlite3.gz ../. | ||
+ | # Clear tmp folder | ||
+ | rm $LOG_DIR/ | ||
- | # because login and pass for the ftp connection are unencrypted you can restrict read/write access mode to the file with chmod command) | ||
- | wget --user=admin --password=' | ||
</ | </ | ||
+ | |||
+ | <WRAP center round tip 60%> | ||
+ | Do not forget to grant additional run permissions | ||
+ | </ | ||
+ | chmod u+x / | ||
+ | |||
Add the script to the //crontab// with the parameters: | Add the script to the //crontab// with the parameters: | ||
- | 10 0 * * * / | + | 10 0 * * * / |
to run it every day at 00:10 | to run it every day at 00:10 | ||
+ | |||
New files will only be added to ~/ | New files will only be added to ~/ |
backing_up_your_data.1627557857.txt.gz · Last modified: 2021/07/29 11:24 by atolstov