diff --git a/README.md b/README.md index 1249a1acef51c25cedda5705cbe39e955490312b..c73ee8e2fdddb3ee9cccd5b480abc51ce50cf4df 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ RESTIC * encrypts data * deduplicates files * delete backups by rules to keep a count of hourly, daily, weekly, mothly, yearly backups -* several backup targets (we currently use sftp:// http:// and file://) +* several backup targets (we currently use sftp:// https:// and file://) ### control simoultanous backups ### @@ -186,10 +186,66 @@ TODO: advanced stuff ... There is a possibility for directory based include and ### Setup the target ### -incl. test transfer to storage +Edit **jobs/transfer.job**. This file handles the transfer of local directories +to a backup target. You find comments in the config. + +By default the backp tool "restic" is activated (and recommended). You can switch to duplicity +if you feel familiar with it. + +`bin = restic` + +Create a repository base directory with the wanted protocol. This step has to be done +once for all systems you want to backup. The IML Backup will create a subdirectory +with the hostname for its backups. Set your target in storage: + +`storage = sftp://backup@storage.example.com//netshare/backup` ## Production usage ## +Edit **jobs/transfer.job**. + +Set a password to encrypt local data with it. Each system should have its own password. +Use a long password - i.e. 128 characters. +Save your password list - if you loose it you cannot restore data anymore. + +`passphrase = EnterYourSecretHere` + +Change the restore path if needed. A restore does not overwrite the current files. + +`restore-path = /restore` + +Then have a look to the section with variables that have the prefix of bin = ... (restic_... or duplicity_...). + +The index files are stored in $HOME. Because /root partition could be to small for +systems with many files (fileserver) you can put the index somewhere else: + +`*_cachedir = ...` + +With this loglevel you get a list of new or changed files in the log: + +`restic_verbose = 2` + +You can set a tag that is set for backups by script. + +`restic_tag = imlbackup` + +The mount of backup sets is a restic feature. After mounting a backup there +you can browse via filesystem through backups and timestamps. + +`restic_mountpoint = /mnt/restore` + +Define how many backups you wanto to keep. After the backup of a directory +the cleanup strategy will be applied. + +``` +# prune +restic_keep-hourly = 100 +restic_keep-daily = 90 +restic_keep-weekly = 12 +restic_keep-monthly = 12 +restic_keep-yearly = 10 +``` + ### setup backup times ### ### Create a cronjob ### diff --git a/transfer.sh b/transfer.sh index 36830afb1ece9b136f546dff6c4aa26a52fbe198..70b2ba3d1895f53928333acfb81cc7494b9f38dd 100755 --- a/transfer.sh +++ b/transfer.sh @@ -7,6 +7,8 @@ # transfer.sh - incremental backup # transfer.sh full - full backup # transfer.sh dumps - transfer local dumps only +# transfer.sh prune - cleanup backup data +# transfer.sh help - show help # # -------------------------------------------------------------------------------- # ah - Axel Hahn <axel.hahn@iml.unibe.ch> @@ -26,6 +28,7 @@ # 2020-02-25 ah,ds, v1.11 fix test -z with non existing vars; show final backup status # 2021-01-29 ah,ds, v1.12 abort on empty passphrase # 2021-05-19 ah,ds, v2.0 plugin driven to support multiple backup tools (duplicity + restic) +# 2021-12-02 ah v2.1 added parameter "prune" to cleanup only # ================================================================================ @@ -38,7 +41,10 @@ . `dirname $0`/jobhelper.sh . `dirname $0`/inc_bash.sh - typeset -i rc=0 + typeset -i rc=0 + typeset -i doBackup=1 + typeset -i doPrune=1 + if [ ! -r "${DIRFILE}" -o ! -r "${STORAGEFILE}" ]; then echo "SKIP backup of local files - one of the files is not readable (no error): ${DIRFILE} | ${STORAGEFILE}" exit 0 @@ -104,10 +110,29 @@ # MAIN # -------------------------------------------------------------------------------- + if [ "$1" = "help" -o "$1" = "-h" -o "$1" = "-?" ]; then + echo "HELP: + + Transfer local files to a backup target. + + target ${STORAGE_BASEDIR} + backup tool $STORAGE_BIN + + PARAMETERS: + transfer.sh - incremental backup + transfer.sh full - full backup + transfer.sh dumps - transfer local dumps only + transfer.sh prune - cleanup backup data only (no backup) + transfer.sh help - show this help (works with -h and -? too) + " + exit 0 + fi + if [ "$1" = "prune" ]; then + doBackup=0 + fi - h1 `date` TRANSFER LOCAL DATA TO STORAGE | tee -a $transferlog - + echo "METHOD : $METHOD" | tee -a $transferlog echo "TARGET : ${STORAGE_BASEDIR}" | tee -a $transferlog echo "REGISTER : ${STORAGE_REGISTER}" | tee -a $transferlog @@ -269,36 +294,43 @@ # --- backup h3 "`date` Backup ${mydir}" - - sCmd="$( t_backupDirGetCmdBackup )" - echo "what: ${mydir}" - echo "target: ${sTarget}" - echo "command: $sCmd" - echo - color cmd - $sCmd - fetchrc - color reset - echo - - t_rcCheckBackup $myrc - - if [ $myrc -ne 0 ]; then - color error - echo DIR ERROR ${mydir} rc=$myrc during file transfer - + if [ $doBackup -eq 0 ]; then + echo "SKIP backup" else - color ok - echo DIR OK ${mydir} was successful. + sCmd="$( t_backupDirGetCmdBackup )" + echo "what: ${mydir}" + echo "target: ${sTarget}" + echo "command: $sCmd" + echo + color cmd + $sCmd + fetchrc + color reset + echo + + t_rcCheckBackup $myrc + + if [ $myrc -ne 0 ]; then + color error + echo DIR ERROR ${mydir} rc=$myrc during file transfer + + else + color ok + echo DIR OK ${mydir} was successful. + fi + color reset fi - color reset echo # --- post action h3 "`date` POST backup task for ${mydir}" - t_backupDirDoPostTasks - echo + if [ $doPrune -eq 0 ]; then + echo "SKIP prune" + else + t_backupDirDoPostTasks + echo + fi echo else