Skip to content
Snippets Groups Projects
Commit 7ca3770b authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'desktop-notify' into 'master'

Desktop notification

See merge request !101
parents 562c31fd 998e7e12
No related branches found
No related tags found
1 merge request!101Desktop notification
......@@ -177,6 +177,7 @@ EOFbackupinfo
if [ $bStart -eq 1 ]; then
j_notify "Start" "Starting a backup run..."
_j_runHooks "100-before-backup"
sleep 3
......@@ -194,6 +195,7 @@ EOFbackupinfo
"${DIR_SELF}"/localdump.sh ALL | tee -a "$JOB_LOGFILE"
rcBackup=$?
test $rcBackup -gt 0 && j_notify "db dumps" "rc=$rcBackup" $rcBackup
echo "INFO: $(date) - local backups were finished" | tee -a "$JOB_LOGFILE"
echo
......@@ -260,6 +262,7 @@ EOFbackupinfo
# --------------------------------------------------------------------------------
j_notify "Done" "Backup was finished. rc=$rcBackup. See log for details: $JOB_LOGFILE" $rcBackup
exit $rcBackup
......
......@@ -150,11 +150,14 @@ else
fi
echo ">>> Summary of database backup actions:"
cat $logfile | grep "__[A-Z][A-Z]*__" | grep '__DB__' | filterColor
cat $logfile | grep '__DB__' | filterColor | cut -f 1 -d ' ' | sort -u | while read -r dbprefix
do
( grep "$dbprefix SKIP" $logfile || grep "$dbprefix " $logfile ) | cut -f 2- -d ':'
done
echo
echo ">>> Summary of transfer actions:"
cat $logfile | grep "__[A-Z][A-Z]*__" | grep -E '__(BACKUP|PRUNE|REPO|VERIFY)__' | filterColor
cat $logfile | grep -E '__(BACKUP|PRUNE|REPO|VERIFY)__' | filterColor
echo
sShort="$sShort - OK: $iOK ... Errors: $iError"
......
......@@ -144,12 +144,14 @@ See [Hooks](50_Hooks/_index.md)
## Restic ##
* creates one initial full backup - and then never again.
* creates one initial full backup - and then never again (then it starts incremental backups only).
* encrypts data
* deduplicates files
* delete backups by rules to keep a count of hourly, daily, weekly, mothly, yearly backups
* several backup targets (currently supported protocols: sftp:// https:// and file://)
* Single binary (written in Go)
* MS Windows: Backup uses volume shadow copy service (vss)
* Linux: with Fuse you can browse you can mount the backup repository and browse through all snapshots
## Duplicity ##
......
# What you need to run:
* GNU core utilities
* Linux: On a basic linux installation it will run "out of the box"
* MS Windows: You need a set of GNU tools.
* Cygwin: https://cygwin.com/
* MINGW: https://www.mingw-w64.org/
* Bash
* MS Windows: You can add let open .sh files with bash
* Restic
* see the Docs https://restic.readthedocs.io/en/latest/020_installation.html
* Get the binary from your package manager or https://github.com/restic/restic/releases
* if you don't have the binary in a directory of $PATH you can add it in the environment of the backup. See Configuration -> File env.
\ No newline at end of file
......@@ -9,7 +9,7 @@
## Installation with git clone
The most easy way is to use git pull.
The most easy way to install it and keep it up to date is to use `git clone|pull`.
If you don't have / want to use git see the next chapter "Manual installation: uncompress archive".
As user **root**:
......
......@@ -78,6 +78,21 @@ because of a wrong exclude pattern.
`exclude = /tmp/.*`
# Hints for MS Windows #
To define folders to backup you should not use the bash unix like notation with forward slash eg. `/c/your/path`.
There seems to be a bug in restic to show snapshots on MS Windows written with /.
https://github.com/restic/restic/issues/2397
Use the backslash - and quote it, eg:
```txt
include = c:\\backup
include = c:\\inetpub
include = c:\\scripts
include = c:\\Users
```
## TODO: custom single dirs with includes and exludes ##
TODO.
```
## Typical Usage
This is the main script to start a backup. The script *backup.sh* is the one to add as a cronjob. It will start
* the dumps of local databases
* the file transfer to an external repository
Both of these steps can be started seperately (see next pages).
## Typical Usage
* on Linux: as a non root user use sudo `sudo ./backup.sh`
* on MS Windows: start it as user `./backup.sh`. Or double click it in a file manager (e.g. Explorer). The first time it asks what program should be used to open *.sh files - select the bash.exe ornavigate to it.
## Help
```txt
# ./backup.sh -?
___ ___ ___ ___ _______ __
......
## Make database dumps ##
## Make database dumps
To create backup dumps we use `./localdump.sh`
To create backup database dumps without transfer of local directory to a backup target use `sudo ./localdump.sh`.
Backup dumps will be stored as gzip files into `/var/iml-backup/[service]`.
## Help
```text
SYNTAX:
......@@ -20,7 +23,7 @@ ldap
mysql
pgsql
sqlite
```text
```
If you have local Mysql daemon or Pgsql you can test it by starting
......@@ -43,7 +46,7 @@ To dump schemes of a specific database type add the name of a known service.
sudo ./localdump.sh mysql
```
## Structure in the backup folder ##
## Structure in the backup folder
In the database dump folder is a subdir per service `/var/iml-backup/[service]`.
......@@ -54,7 +57,7 @@ All dumps are gzip compressed.
At the end of a backup task with localdump.sh older files older than *keep-days*
will be deleted from `/var/iml-backup/[service]`.
### Backup sqlite ###
### Backup sqlite
Keep in mind that you need to define sqlite databases in jobs/backup-dbfiles.job first.
......@@ -70,10 +73,11 @@ In the folder /var/iml-backup/sqlite/ it creates 2 files per database
* the gzip compressed dump (filename is full path with replacing `/` by `_`)
* a .META file that contains the original full path for restore
## Restore database dumps ##
## Restore database dumps
Remark:
To make a database restore its dump must be located at this directory.
To make a database restore its dump must be located at this directory:
`/var/iml-backup/[service]`
The value keepdays contains number of days how long to keep dumps locally.
If your dump to restore is older than this given range then you need
......
```
## Transfer files ##
To transfer local directories to a backup repository use `sudo ./transfer.sh`.
```txt
> ./transfer.sh -h
___ ___ ___ ___ _______ __
......
......@@ -44,3 +44,18 @@ $ cat /etc/cron.d/client-backup
7 18 * * 6 root /usr/local/bin/cronwrapper.sh 1440 /opt/imlbackup/client/prune.sh 'iml-backup-prune'
7 18 * * 0 root /usr/local/bin/cronwrapper.sh 1440 /opt/imlbackup/client/verify.sh 'iml-backup-verify'
```
## Desktop notification
If you don't run the backup on a server but on a client you can activate the desktop notification for a user that is logged in.
Set a variable `SUPER_USER=<USERNAME>` in your cron file.
Example:
```shell
$ cat /etc/cron.d/client-backup
SUPER_USER=axel
*/17 * * * root /usr/local/bin/cronwrapper.sh 1440 /opt/imlbackup/client/backup.sh 'iml-backup'
```
......@@ -14,6 +14,7 @@
# 2018-02-13 ah,ds v1.3 detect samba shares based on a flag
# 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space"
# 2023-03-17 ah v1.5 ignore required user on MS windows; source jobs/env if it exists; use varaiable FQDN
# 2023-04-12 ah v1.6 add desktop notification
# ================================================================================
......@@ -82,6 +83,11 @@ function j_init(){
j_requireBinary "tee"
j_requireBinary "touch"
# for notify-send in j_notify()
if [ -n "$SUDO_USER" ]; then
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u $SUDO_USER)/bus
fi
# j_read
}
......@@ -419,6 +425,30 @@ function _getFqdn(){
# echo "INFO: FQDN is [$FQDN]"
}
# show a desktop notification using notify-send
# param string summary (aka title)
# param string message text
# paran integer optional: exitcode; if set it adds a prefix OK or ERRROR on summary and sets urgency on error
function j_notify(){
local _summary="IML BACKUP :: $1"
local _body="$( date +%H:%M:%S ) $2"
local _rc="$3"
local _urgency="normal"
if [ -n "$DBUS_SESSION_BUS_ADDRESS" ]; then
if [ -n "$_rc" ]; then
if [ "$_rc" = "0" ]; then
_summary="OK: ${_summary}"
else
_summary="ERROR: ${_summary}"
_urgency="critical"
fi
fi
su "$SUDO_USER" -c "notify-send --urgency=${_urgency} '${_summary}' '${_body}'"
fi
}
# ------------------------------------------------------------
# check if it was startet with a given user
# This is skipped if MS windows was detected with "mingw".
......
......@@ -357,6 +357,7 @@
_j_runHooks "200-before-db-service"
. $BACKUP_SCRIPT $mode
test $rc -gt 0 && j_notify "db ${SERVICENAME}" "$BACKUP_SCRIPT $mode was finished with rc=$rc" $rc
_j_runHooks "230-after-db-service" "$rc"
# ----- post jobs: cleanup
......
......@@ -125,7 +125,7 @@ function restoreByFile(){
checkRequirements >/dev/null 2>&1
if [ $SERVICEFOUND -eq 0 ]; then
echo "__DB__$SERVICENAME INFO: service [$SERVICENAME] is not avilable on this machine."
echo "__DB__$SERVICENAME SKIP: service [$SERVICENAME] is not avilable on this machine."
fi
case $1 in
......
......@@ -31,6 +31,10 @@ FILEDEFS=${DIR_JOBS}/backup-dbfiles.job
# make sqlite3 backups of all sqlite = ... in backup-dbfiles.job
function doSqliteBackup(){
if ! _j_getvar ${FILEDEFS} "sqlite" | grep . ; then
echo "__DB__$SERVICENAME SKIP: no entries found for sqlite."
return 0
fi
create_targetdir
......@@ -56,17 +60,9 @@ function doSqliteBackup(){
# echo -n " to $TARGET "
sqlite3 "$DATABASE_FILE" .dump >"${TARGET}"
fetchrc >/dev/null
db._compressDumpfile "${TARGET}"
# $myrc is last returncode - set in fetchrc
# if [ $myrc -eq 0 ]; then
# echo -n "gzip ... "
# compress_file "${TARGET}"
# echo "$DATABASE_FILE" >"${META}"
# else
# echo "ERROR occured - no gzip"
# fi
# ls -l ${TARGET}*
db._compressDumpfile "${TARGET}" && echo "$DATABASE_FILE" >"${META}"
ls -l ${TARGET}*
fi
fi
......
......@@ -406,6 +406,8 @@ function setAction(){
echo
t_rcCheckBackup $myrc "${BACKUP_DIR}"
test $myrc -ne 0 && j_notify "Dir ${BACKUP_DIR}" "Backup for ${BACKUP_DIR} failed with rc=$myrc. See log for details: $JOB_LOGFILE" 1
_j_runHooks "320-after-folder-transfer" "$myrc"
fi
......@@ -451,6 +453,7 @@ function setAction(){
touch "${lastprunefile}"
else
rc+=1
j_notify "Prune" "Pruning old data in the repostitory failed." 1
fi
ls -l "${lastprunefile}"
echo
......@@ -466,6 +469,7 @@ function setAction(){
touch "${lastverifyfile}"
else
rc+=1
j_notify "Verify" "Verify of repository data failed." 1
fi
ls -l "${lastverifyfile}"
echo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment