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

Merge branch '5814-migrate-repo-to-v2' into 'master'

5814 migrate repo to v2 - rename hooks

See merge request !88
parents 484384e1 d9f6f8f3
No related branches found
No related tags found
1 merge request!885814 migrate repo to v2 - rename hooks
Showing
with 135 additions and 32 deletions
...@@ -6,5 +6,9 @@ keys/* ...@@ -6,5 +6,9 @@ keys/*
logs/auto-* logs/auto-*
logs/full-* logs/full-*
logs/inc-* logs/inc-*
logs/last*
logs/prune*
logs/transfer-* logs/transfer-*
*lastlog logs/transfer.running
\ No newline at end of file *lastlog
static/*
\ No newline at end of file
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# #
# 2022-01-14 ah v1.0 # 2022-01-14 ah v1.0
# 2022-02-10 ah v1.1 handle local dumps only; improve infos # 2022-02-10 ah v1.1 handle local dumps only; improve infos
# 2022-11-04 ah v1.2 rename hooks
# ================================================================================ # ================================================================================
. $( dirname "$0" )/jobhelper.sh . $( dirname "$0" )/jobhelper.sh
...@@ -176,7 +177,7 @@ EOFbackupinfo ...@@ -176,7 +177,7 @@ EOFbackupinfo
if [ $bStart -eq 1 ]; then if [ $bStart -eq 1 ]; then
_j_runHooks "10-before-backup" _j_runHooks "100-before-backup"
sleep 3 sleep 3
......
...@@ -11,21 +11,21 @@ We have hooks "before" a step starts and "afterwards". ...@@ -11,21 +11,21 @@ We have hooks "before" a step starts and "afterwards".
In the IML Backup exist the following hooks In the IML Backup exist the following hooks
| Hook | where | description | Hook | where | description
|--- |--- |--- |--- |--- |---
| 10-before-backup | backup.sh | at the beginning of the backup | 100-before-backup | backup.sh | at the beginning of the backup
| 12-before-db-service | localdump.sh | before starting a backup of a backup type (mysql, sqlite, ...) | 200-before-db-service | localdump.sh | before starting a backup of a backup type (mysql, sqlite, ...)
| 14-before-db-dump | unused | 210-before-db-dump | unused
| 16-after-db-dump | unused | 220-after-db-dump | unused
| 18-after-db-service | localdump.sh | after finishing a database type | 230-after-db-service | localdump.sh | after finishing a database type
| 20-before-transfer | transfer.sh | before starting transfer of all directories | 300-before-transfer | transfer.sh | before starting transfer of all directories
| 22-before-folder-transfer| transfer.sh | before starting transfer of a single directory | 310-before-folder-transfer| transfer.sh | before starting transfer of a single directory
| 24-after-folder-transfer | transfer.sh | after transfer of a single directory | 320-after-folder-transfer | transfer.sh | after transfer of a single directory
| 26-after-prune | transfer.sh | after pruning data | 330-after-prune | transfer.sh | after pruning data
| 28-after-verify | transfer.sh | after verifying data | 340-after-verify | transfer.sh | after verifying data
| 30-post-backup | transfer.sh | after all backup steps | 400-post-backup | transfer.sh | after all backup steps
At the beginning the startup hook (10-before-backup) and the post hook (30-post-backup) for triggering a message might be the most common to use. At the beginning the startup hook (100-before-backup) and the post hook (400-post-backup) for triggering a message might be the most common to use.
## Subdirs of a hook dir ## Subdirs of a hook dir
...@@ -49,37 +49,37 @@ After execution of the scripts of "on-ok" or "on-error" additionally the found s ...@@ -49,37 +49,37 @@ After execution of the scripts of "on-ok" or "on-error" additionally the found s
```txt ```txt
> tree -d hooks/ > tree -d hooks/
hooks/ hooks/
|-- 10-before-backup |-- 100-before-backup
| `-- always | `-- always
|-- 12-before-db-service |-- 200-before-db-service
| `-- always | `-- always
|-- 14-before-db-dump |-- 210-before-db-dump
| `-- always | `-- always
|-- 16-after-db-dump |-- 220-after-db-dump
| |-- always | |-- always
| |-- on-error | |-- on-error
| `-- on-ok | `-- on-ok
|-- 18-after-db-service |-- 230-after-db-service
| |-- always | |-- always
| |-- on-error | |-- on-error
| `-- on-ok | `-- on-ok
|-- 20-before-transfer |-- 300-before-transfer
| `-- always | `-- always
|-- 22-before-folder-transfer |-- 310-before-folder-transfer
| `-- always | `-- always
|-- 24-after-folder-transfer |-- 320-after-folder-transfer
| |-- always | |-- always
| |-- on-error | |-- on-error
| `-- on-ok | `-- on-ok
|-- 26-after-prune |-- 330-after-prune
| |-- always | |-- always
| |-- on-error | |-- on-error
| `-- on-ok | `-- on-ok
|-- 28-after-verify |-- 340-after-verify
| |-- always | |-- always
| |-- on-error | |-- on-error
| `-- on-ok | `-- on-ok
`-- 30-post-backup `-- 400-post-backup
|-- always |-- always
|-- on-error |-- on-error
`-- on-ok `-- on-ok
...@@ -96,9 +96,9 @@ When processing a hook all files will be sorted in alphabetic order. Files start ...@@ -96,9 +96,9 @@ When processing a hook all files will be sorted in alphabetic order. Files start
Before the backup starts we want to update some local information that we want to put as latest information. Before the backup starts we want to update some local information that we want to put as latest information.
I have a script that gets the list of installed linux packages as a textfile. If my system is damaged and I need to reinstall it this list will help me to reinstall all applications and libraries. I have a script that gets the list of installed linux packages as a textfile. If my system is damaged and I need to reinstall it this list will help me to reinstall all applications and libraries.
If my bash script that does the job is `/home/axel/scripts/list_packages.sh` ... and we let it run on each start of the backup. That's why we use the *10-before-backup* hook: If my bash script that does the job is `/home/axel/scripts/list_packages.sh` ... and we let it run on each start of the backup. That's why we use the *100-before-backup* hook:
Create a file named *hooks/10-before-backup/always/10_list_packages.sh* which has the content: Create a file named *hooks/100-before-backup/always/10_list_packages.sh* which has the content:
```sh ```sh
#!/usr/bin/env bash #!/usr/bin/env bash
...@@ -107,8 +107,8 @@ Create a file named *hooks/10-before-backup/always/10_list_packages.sh* which ha ...@@ -107,8 +107,8 @@ Create a file named *hooks/10-before-backup/always/10_list_packages.sh* which ha
If you have the installation in a user directory keep in mind that the backup runs as root. Set executable permissions for root. If owner and group is your user then set exection permissions for the world: 0755: If you have the installation in a user directory keep in mind that the backup runs as root. Set executable permissions for root. If owner and group is your user then set exection permissions for the world: 0755:
```sh ```sh
> chmod 0755 hooks/10-before-backup/always/10_list_packages.sh > chmod 0755 hooks/100-before-backup/always/10_list_packages.sh
> ls -l hooks/10-before-backup/always > ls -l hooks/100-before-backup/always
total 4 total 4
-rwxr-xr-x 1 axel axel 79 Oct 7 22:36 10_get_installed_packages.sh -rwxr-xr-x 1 axel axel 79 Oct 7 22:36 10_get_installed_packages.sh
``` ```
#!/bin/bash
# ===============================================================
#
# HELPER: move existing hooks to new hook structure
#
# ---------------------------------------------------------------
# 2022-11-04 axel.hahm@iml.unibe.ch
# ===============================================================
cd "$( dirname $0 )/../hooks"
# ---------------------------------------------------------------
# CONFIG
# ---------------------------------------------------------------
typeset -i iFound=0
declare -a aOldHooks=(
10-before-backup
12-before-db-service
14-before-db-dump
16-after-db-dump
18-after-db-service
20-before-transfer
22-before-folder-transfer
24-after-folder-transfer
26-after-prune
28-after-verify
30-post-backup
)
declare -a aNewHooks=(
100-before-backup
200-before-db-service
210-before-db-dump
220-after-db-dump
230-after-db-service
300-before-transfer
310-before-folder-transfer
320-after-folder-transfer
330-after-prune
340-after-verify
400-post-backup
)
# ---------------------------------------------------------------
# MAIN
# ---------------------------------------------------------------
echo
echo ===== HELPER: move existing hooks to new hook structure =====
echo
for i in ${!aOldHooks[@]}
do
hookfrom=${aOldHooks[$i]}
hookto=${aNewHooks[$i]}
if [ -d "$hookto" ]; then
if [ -d "$hookfrom" ]; then
echo " SCAN for $hookfrom ... "
for myfile in $( find $hookfrom -type f | grep -v ".gitignore" )
do
tofile=$( echo $myfile | sed "s#$hookfrom#$hookto#" )
echo -n " MOVE $myfile -> $tofile ... "
mv "$myfile" "$tofile" && echo "OK" || echo "FAILED"
iFound+=1
done
find $hookfrom -type f | grep -v ".gitignore" && echo " WARNING: some files are still in [$hookfrom] " || (
echo -n " no more files ... REMOVE [$hookfrom] ... "
rm -rf "$hookfrom" && echo "OK" || echo "FAILED"
)
echo
else
echo "SKIP $hookto - nothing to do."
fi
else
echo "ERROR: hook dir $hookto does not exist"
fi
done
echo "----------------------------------------------------------------------"
echo "moved files: $iFound"
# ---------------------------------------------------------------
#!/bin/bash
echo -n "UPGRADE: REPO ... "
if eval restic migrate $ARGS_DEFAULT | grep upgrade_repo_v2; then
echo "need to update to v2"
eval restic migrate upgrade_repo_v2
else
echo "up to date"
fi
sleep 3
# sleep 100
# exit
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment