-
-
Save pavoldomin/82017c57797357fc2e35 to your computer and use it in GitHub Desktop.
ReaR: separate OUTPUT_URL from BACKUP_URL handling, regardless BACKUP method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/usr/share/rear/backup/NETFS/default/15_save_copy_of_prefix_dir.sh b/usr/share/rear/backup/NETFS/default/15_save_copy_of_prefix_dir.sh | |
index c56b543..1c28773 100644 | |
--- a/usr/share/rear/backup/NETFS/default/15_save_copy_of_prefix_dir.sh | |
+++ b/usr/share/rear/backup/NETFS/default/15_save_copy_of_prefix_dir.sh | |
@@ -6,7 +6,7 @@ | |
url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
local scheme=$(url_scheme ${!url}) | |
local path=$(url_path ${!url}) | |
-local opath=$(output_path $scheme $path) | |
+local opath=$(backup_path $scheme $path) | |
# if $opath is empty return silently (e.g. scheme tape) | |
[ -z "$opath" ] && return 0 | |
diff --git a/usr/share/rear/backup/NETFS/default/20_make_prefix_dir.sh b/usr/share/rear/backup/NETFS/default/20_make_prefix_dir.sh | |
index 3eeb1b4..db15bca 100644 | |
--- a/usr/share/rear/backup/NETFS/default/20_make_prefix_dir.sh | |
+++ b/usr/share/rear/backup/NETFS/default/20_make_prefix_dir.sh | |
@@ -5,7 +5,7 @@ | |
url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
local scheme=$(url_scheme ${!url}) | |
local path=$(url_path ${!url}) | |
-local opath=$(output_path $scheme $path) | |
+local opath=$(backup_path $scheme $path) | |
# if $opath is empty return silently (e.g. scheme tape) | |
[ -z "$opath" ] && return 0 | |
diff --git a/usr/share/rear/backup/NETFS/default/25_create_lock.sh b/usr/share/rear/backup/NETFS/default/25_create_lock.sh | |
index 1f08230..59090a2 100644 | |
--- a/usr/share/rear/backup/NETFS/default/25_create_lock.sh | |
+++ b/usr/share/rear/backup/NETFS/default/25_create_lock.sh | |
@@ -5,7 +5,7 @@ | |
url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
local scheme=$(url_scheme ${!url}) | |
local path=$(url_path ${!url}) | |
-local opath=$(output_path $scheme $path) | |
+local opath=$(backup_path $scheme $path) | |
# if $opath is empty return silently (e.g. scheme tape) | |
[ -z "$opath" ] && return 0 | |
diff --git a/usr/share/rear/backup/NETFS/default/50_make_backup.sh b/usr/share/rear/backup/NETFS/default/50_make_backup.sh | |
index 834aa7d..b2c862c 100644 | |
--- a/usr/share/rear/backup/NETFS/default/50_make_backup.sh | |
+++ b/usr/share/rear/backup/NETFS/default/50_make_backup.sh | |
@@ -31,7 +31,7 @@ done < $TMP_DIR/backup-exclude.txt | |
local scheme=$(url_scheme $BACKUP_URL) | |
local path=$(url_path $BACKUP_URL) | |
-local opath=$(output_path $scheme $path) | |
+local opath=$(backup_path $scheme $path) | |
if [[ "$opath" ]]; then | |
mkdir -p $v "${opath}" >&2 | |
diff --git a/usr/share/rear/backup/NETFS/default/97_remove_lock.sh b/usr/share/rear/backup/NETFS/default/97_remove_lock.sh | |
index 165a0a1..f69f7bd 100644 | |
--- a/usr/share/rear/backup/NETFS/default/97_remove_lock.sh | |
+++ b/usr/share/rear/backup/NETFS/default/97_remove_lock.sh | |
@@ -1,7 +1,8 @@ | |
# remove the lockfile | |
-local scheme=$(url_scheme $OUTPUT_URL) | |
-local path=$(url_path $OUTPUT_URL) | |
-local opath=$(output_path $scheme $path) | |
+url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
+local scheme=$(url_scheme ${!url}) | |
+local path=$(url_path ${!url}) | |
+local opath=$(backup_path $scheme $path) | |
# if $opath is empty return silently (e.g. scheme tape) | |
[ -z "$opath" ] && return 0 | |
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf | |
index b138eec..79a8a06 100644 | |
--- a/usr/share/rear/conf/default.conf | |
+++ b/usr/share/rear/conf/default.conf | |
@@ -119,6 +119,10 @@ OUTPUT_URL= | |
OUTPUT_OPTIONS= | |
OUTPUT_MOUNTCMD= | |
OUTPUT_UMOUNTCMD= | |
+OUTPUT_PREFIX="$HOSTNAME" | |
+# keep an older copy of the output (mv $OUTPUT_PREFIX $OUTPUT_PREFIX.old before we copy the new version) | |
+# empty means only keep current output | |
+KEEP_OLD_OUTPUT_COPY= | |
## | |
# OUTPUT=RAMDISK stuff | |
diff --git a/usr/share/rear/lib/global-functions.sh b/usr/share/rear/lib/global-functions.sh | |
index 9aa3d8d..1bc74ac 100644 | |
--- a/usr/share/rear/lib/global-functions.sh | |
+++ b/usr/share/rear/lib/global-functions.sh | |
@@ -48,7 +48,7 @@ url_path() { | |
echo /${path#*/} | |
} | |
-output_path() { | |
+backup_path() { | |
local scheme=$1 | |
local path=$2 | |
case $scheme in | |
@@ -65,6 +65,24 @@ output_path() { | |
echo "$path" | |
} | |
+output_path() { | |
+ local scheme=$1 | |
+ local path=$2 | |
+ case $scheme in | |
+ (tape) # no path for tape required | |
+ path="" | |
+ ;; | |
+ (file) # type file needs a local path (must be mounted by user) | |
+ path="$path/${OUTPUT_PREFIX}" | |
+ ;; | |
+ (*) # nfs, cifs, usb, a.o. need a temporary mount-path | |
+ path="${BUILD_DIR}/outputfs/${OUTPUT_PREFIX}" | |
+ ;; | |
+ esac | |
+ echo "$path" | |
+} | |
+ | |
+ | |
### Mount URL $1 at mountpoint $2[, with options $3] | |
mount_url() { | |
local url=$1 | |
diff --git a/usr/share/rear/output/ISO/Linux-i386/90_transfer_image.sh b/usr/share/rear/output/ISO/Linux-i386/90_transfer_image.sh | |
deleted file mode 100644 | |
index 407066e..0000000 | |
--- a/usr/share/rear/output/ISO/Linux-i386/90_transfer_image.sh | |
+++ /dev/null | |
@@ -1,38 +0,0 @@ | |
-# This script copies the ISO image to the target location in OUTPUT_URL | |
- | |
-# Check if ISO image is available | |
-[[ -s "$ISO_DIR/$ISO_PREFIX.iso" ]] | |
-StopIfError "Image $ISO_DIR/$ISO_PREFIX.iso is missing or empty." | |
- | |
-# Check if we have a target location OUTPUT_URL | |
-if [[ -z "$OUTPUT_URL" ]]; then | |
- return | |
-fi | |
- | |
-local scheme=$(url_scheme $OUTPUT_URL) | |
-local server=$(url_host $OUTPUT_URL) | |
-local path=$(url_path $OUTPUT_URL) | |
- | |
-case "$scheme" in | |
- (nfs|cifs|usb|tape|file|sshfs) | |
- if [[ "$BACKUP" != "NETFS" ]] ; then | |
- local opath=$(output_path $scheme $path) | |
- LogPrint "Transferring ISO image to $OUTPUT_URL." | |
- cp $v $ISO_DIR/$ISO_PREFIX.iso $opath/ >&2 | |
- fi | |
- ;; | |
- (fish|ftp|ftps|hftp|http|https|sftp) | |
- LogPrint "Transferring ISO image to $OUTPUT_URL" | |
- lftp -c "open $OUTPUT_URL; mput $ISO_DIR/$ISO_PREFIX.iso" | |
- StopIfError "Problem transferring ISO image to $OUTPUT_URL" | |
- ;; | |
- (rsync) | |
- if [[ "$BACKUP" != "NETFS" ]] && [[ "$BACKUP" != "RSYNC" ]] ; then | |
- # BACKUP=NETFS/RSYNC - iso is copied via result_files[] | |
- LogPrint "Transferring ISO image to $OUTPUT_URL" | |
- rsync -a $v "$ISO_DIR/$ISO_PREFIX.iso" "$OUTPUT_URL" | |
- StopIfError "Problem transferring ISO image to $OUTPUT_URL" | |
- fi | |
- ;; | |
- (*) BugError "Support for $scheme is not implemented yet.";; | |
-esac | |
diff --git a/usr/share/rear/output/NETFS/default/15_save_copy_of_prefix_dir.sh b/usr/share/rear/output/NETFS/default/15_save_copy_of_prefix_dir.sh | |
deleted file mode 120000 | |
index 1409ce9..0000000 | |
--- a/usr/share/rear/output/NETFS/default/15_save_copy_of_prefix_dir.sh | |
+++ /dev/null | |
@@ -1 +0,0 @@ | |
-../../../backup/NETFS/default/15_save_copy_of_prefix_dir.sh | |
\ No newline at end of file | |
diff --git a/usr/share/rear/output/NETFS/default/20_make_prefix_dir.sh b/usr/share/rear/output/NETFS/default/20_make_prefix_dir.sh | |
deleted file mode 120000 | |
index d9d30ef..0000000 | |
--- a/usr/share/rear/output/NETFS/default/20_make_prefix_dir.sh | |
+++ /dev/null | |
@@ -1 +0,0 @@ | |
-../../../backup/NETFS/default/20_make_prefix_dir.sh | |
\ No newline at end of file | |
diff --git a/usr/share/rear/output/NETFS/default/25_create_lock.sh b/usr/share/rear/output/NETFS/default/25_create_lock.sh | |
deleted file mode 120000 | |
index 947129b..0000000 | |
--- a/usr/share/rear/output/NETFS/default/25_create_lock.sh | |
+++ /dev/null | |
@@ -1 +0,0 @@ | |
-../../../backup/NETFS/default/25_create_lock.sh | |
\ No newline at end of file | |
diff --git a/usr/share/rear/output/NETFS/default/95_copy_result_files.sh b/usr/share/rear/output/NETFS/default/95_copy_result_files.sh | |
deleted file mode 100644 | |
index 58c3b6e..0000000 | |
--- a/usr/share/rear/output/NETFS/default/95_copy_result_files.sh | |
+++ /dev/null | |
@@ -1,49 +0,0 @@ | |
-# | |
-# copy resulting files to network backup location | |
- | |
-local scheme=$(url_scheme $OUTPUT_URL) | |
-local path=$(url_path $OUTPUT_URL) | |
-local opath=$(output_path $scheme $path) | |
- | |
-# if $opath is empty return silently (e.g. scheme tape) | |
-if [[ -z "$opath" || -z "$OUTPUT_URL" || "$scheme" == "obdr" || "$scheme" == "tape" ]]; then | |
- return 0 | |
-fi | |
- | |
-LogPrint "Copying resulting files to $scheme location" | |
- | |
-case "$scheme" in | |
- (nfs|cifs|usb|file|sshfs) | |
- # if called as mkbackuponly then we just don't have any result files. | |
- if test "$RESULT_FILES" ; then | |
- Log "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
- cp $v "${RESULT_FILES[@]}" "${opath}/" >&2 | |
- StopIfError "Could not copy files to $scheme location" | |
- fi | |
- echo "$VERSION_INFO" >"${opath}/VERSION" | |
- StopIfError "Could not create VERSION file on $scheme location" | |
- | |
- cp $v $CONFIG_DIR/templates/RESULT_usage_$OUTPUT.txt "${opath}/README" >&2 | |
- StopIfError "Could not copy usage file to $scheme location" | |
- | |
- # REAR_LOGFILE=/var/log/rear/rear-$HOSTNAME.log (name set by main script) | |
- cat "$REAR_LOGFILE" >"${opath}/rear.log" | |
- StopIfError "Could not copy $REAR_LOGFILE to $scheme location" | |
- ;; | |
- (fish|ftp|ftps|hftp|http|https|sftp) | |
- LogPrint "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
- lftp -c "open $OUTPUT_URL; mput ${RESULT_FILES[@]}" | |
- StopIfError "Problem transferring files to $OUTPUT_URL" | |
- ;; | |
- (rsync) | |
- LogPrint "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
- rsync -a $v "${RESULT_FILES[@]}" "$OUTPUT_URL" | |
- StopIfError "Problem transferring files to $OUTPUT_URL" | |
- ;; | |
- (*) BugError "Support for $scheme is not implemented yet." | |
- ;; | |
-esac | |
- | |
- | |
-Log "Saved $REAR_LOGFILE as rear.log" | |
- | |
diff --git a/usr/share/rear/output/default/15_save_copy_of_prefix_dir.sh b/usr/share/rear/output/default/15_save_copy_of_prefix_dir.sh | |
new file mode 100644 | |
index 0000000..e51b3d8 | |
--- /dev/null | |
+++ b/usr/share/rear/output/default/15_save_copy_of_prefix_dir.sh | |
@@ -0,0 +1,25 @@ | |
+# if KEEP_OLD_OUTPUT_COPY is not empty then move old OUTPUT_PREFIX directory to OUTPUT_PREFIX.old | |
+ | |
+[ -z "${KEEP_OLD_OUTPUT_COPY}" ] && return | |
+ | |
+# do not do this for tapes and special attention for file:///path | |
+url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
+local scheme=$(url_scheme ${!url}) | |
+local path=$(url_path ${!url}) | |
+local opath=$(output_path $scheme $path) | |
+ | |
+# if $opath is empty return silently (e.g. scheme tape) | |
+[ -z "$opath" ] && return 0 | |
+ | |
+if ! test -f "${opath}/.lockfile" ; then | |
+ # lockfile made through workflow backup already (so output keep hands off) | |
+ if test -d "${opath}" ; then | |
+ rm -rf $v "${opath}.old" >&2 | |
+ StopIfError "Could not remove '${opath}.old'" | |
+ mv -f $v "${opath}" "${opath}.old" >&2 | |
+ StopIfError "Could not move '${opath}'" | |
+ fi | |
+else | |
+ Log "Lockfile '${opath}/.lockfile' found. Not keeping old backup data." | |
+fi | |
+# the ${BUILD_DIR}/outputfs/${OUTPUT_PREFIX} will be created by output/default/20_make_prefix_dir.sh | |
diff --git a/usr/share/rear/output/default/20_make_prefix_dir.sh b/usr/share/rear/output/default/20_make_prefix_dir.sh | |
new file mode 100644 | |
index 0000000..d300e4a | |
--- /dev/null | |
+++ b/usr/share/rear/output/default/20_make_prefix_dir.sh | |
@@ -0,0 +1,14 @@ | |
+# if set, create $OUTPUT_PREFIX under the mounted network filesystem share. This defaults | |
+# to $HOSTNAME | |
+ | |
+# do not do this for tapes and special attention for file:///path | |
+url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
+local scheme=$(url_scheme ${!url}) | |
+local path=$(url_path ${!url}) | |
+local opath=$(output_path $scheme $path) | |
+ | |
+# if $opath is empty return silently (e.g. scheme tape) | |
+[ -z "$opath" ] && return 0 | |
+ | |
+mkdir -p $v -m0750 "${opath}" >&2 | |
+StopIfError "Could not mkdir '${opath}'" | |
diff --git a/usr/share/rear/output/default/25_create_lock.sh b/usr/share/rear/output/default/25_create_lock.sh | |
new file mode 100644 | |
index 0000000..781b126 | |
--- /dev/null | |
+++ b/usr/share/rear/output/default/25_create_lock.sh | |
@@ -0,0 +1,16 @@ | |
+# create a lockfile in $OUTPUT_PREFIX to avoid that mkrescue overwrites ISO/PXE/LOGFILE | |
+# made by a previous mkrescue run when the variable KEEP_OLD_OUTPUT_COPY has been set | |
+ | |
+# do not do this for tapes and special attention for file:///path | |
+url="$( echo $stage | tr '[:lower:]' '[:upper:]')_URL" | |
+local scheme=$(url_scheme ${!url}) | |
+local path=$(url_path ${!url}) | |
+local opath=$(output_path $scheme $path) | |
+ | |
+# if $opath is empty return silently (e.g. scheme tape) | |
+[ -z "$opath" ] && return 0 | |
+ | |
+if test -d "${opath}" ; then | |
+ > "${opath}/.lockfile" | |
+ StopIfError "Could not create '${opath}/.lockfile'" | |
+fi | |
diff --git a/usr/share/rear/output/default/95_copy_result_files.sh b/usr/share/rear/output/default/95_copy_result_files.sh | |
new file mode 100644 | |
index 0000000..1910672 | |
--- /dev/null | |
+++ b/usr/share/rear/output/default/95_copy_result_files.sh | |
@@ -0,0 +1,49 @@ | |
+# | |
+# copy resulting files to network output location | |
+ | |
+local scheme=$(url_scheme $OUTPUT_URL) | |
+local path=$(url_path $OUTPUT_URL) | |
+local opath=$(output_path $scheme $path) | |
+ | |
+# if $opath is empty return silently (e.g. scheme tape) | |
+if [[ -z "$opath" || -z "$OUTPUT_URL" || "$scheme" == "obdr" || "$scheme" == "tape" ]]; then | |
+ return 0 | |
+fi | |
+ | |
+LogPrint "Copying resulting files to $scheme location" | |
+ | |
+case "$scheme" in | |
+ (nfs|cifs|usb|file|sshfs) | |
+ # if called as mkbackuponly then we just don't have any result files. | |
+ if test "$RESULT_FILES" ; then | |
+ Log "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
+ cp $v "${RESULT_FILES[@]}" "${opath}/" >&2 | |
+ StopIfError "Could not copy files to $scheme location" | |
+ fi | |
+ echo "$VERSION_INFO" >"${opath}/VERSION" | |
+ StopIfError "Could not create VERSION file on $scheme location" | |
+ | |
+ cp $v $CONFIG_DIR/templates/RESULT_usage_$OUTPUT.txt "${opath}/README" >&2 | |
+ StopIfError "Could not copy usage file to $scheme location" | |
+ | |
+ # REAR_LOGFILE=/var/log/rear/rear-$HOSTNAME.log (name set by main script) | |
+ cat "$REAR_LOGFILE" >"${opath}/rear.log" | |
+ StopIfError "Could not copy $REAR_LOGFILE to $scheme location" | |
+ ;; | |
+ (fish|ftp|ftps|hftp|http|https|sftp) | |
+ LogPrint "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
+ lftp -c "open $OUTPUT_URL; mput ${RESULT_FILES[@]}" | |
+ StopIfError "Problem transferring files to $OUTPUT_URL" | |
+ ;; | |
+ (rsync) | |
+ LogPrint "Copying files '${RESULT_FILES[@]}' to $scheme location" | |
+ rsync -a $v "${RESULT_FILES[@]}" "$OUTPUT_URL" | |
+ StopIfError "Problem transferring files to $OUTPUT_URL" | |
+ ;; | |
+ (*) BugError "Support for $scheme is not implemented yet." | |
+ ;; | |
+esac | |
+ | |
+ | |
+Log "Saved $REAR_LOGFILE as rear.log" | |
+ | |
diff --git a/usr/share/rear/output/default/97_remove_lock.sh b/usr/share/rear/output/default/97_remove_lock.sh | |
new file mode 100644 | |
index 0000000..165a0a1 | |
--- /dev/null | |
+++ b/usr/share/rear/output/default/97_remove_lock.sh | |
@@ -0,0 +1,9 @@ | |
+# remove the lockfile | |
+local scheme=$(url_scheme $OUTPUT_URL) | |
+local path=$(url_path $OUTPUT_URL) | |
+local opath=$(output_path $scheme $path) | |
+ | |
+# if $opath is empty return silently (e.g. scheme tape) | |
+[ -z "$opath" ] && return 0 | |
+ | |
+rm -f $v "${opath}/.lockfile" >&2 | |
diff --git a/usr/share/rear/prep/NETFS/default/07_set_backup_archive.sh b/usr/share/rear/prep/NETFS/default/07_set_backup_archive.sh | |
index bdc8e27..3d9b2e6 100644 | |
--- a/usr/share/rear/prep/NETFS/default/07_set_backup_archive.sh | |
+++ b/usr/share/rear/prep/NETFS/default/07_set_backup_archive.sh | |
@@ -6,7 +6,7 @@ case "$TAPE_DEVICE:$scheme" in | |
(:file) | |
# define the output path according to the scheme | |
local path=$(url_path $BACKUP_URL) | |
- local opath=$(output_path $scheme $path) | |
+ local opath=$(backup_path $scheme $path) | |
backuparchive="${opath}/${BACKUP_PROG_ARCHIVE}${BACKUP_PROG_SUFFIX}${BACKUP_PROG_COMPRESS_SUFFIX}" | |
;; | |
(:*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On branch master | |
# Changes to be committed: | |
# (use "git reset HEAD <file>..." to unstage) | |
# | |
# modified: usr/share/rear/backup/NETFS/default/15_save_copy_of_prefix_dir.sh | |
# modified: usr/share/rear/backup/NETFS/default/20_make_prefix_dir.sh | |
# modified: usr/share/rear/backup/NETFS/default/25_create_lock.sh | |
# modified: usr/share/rear/backup/NETFS/default/50_make_backup.sh | |
# modified: usr/share/rear/backup/NETFS/default/97_remove_lock.sh | |
# modified: usr/share/rear/conf/default.conf | |
# modified: usr/share/rear/lib/global-functions.sh | |
# deleted: usr/share/rear/output/ISO/Linux-i386/90_transfer_image.sh | |
# deleted: usr/share/rear/output/NETFS/default/15_save_copy_of_prefix_dir.sh | |
# deleted: usr/share/rear/output/NETFS/default/20_make_prefix_dir.sh | |
# deleted: usr/share/rear/output/NETFS/default/25_create_lock.sh | |
# new file: usr/share/rear/output/default/15_save_copy_of_prefix_dir.sh | |
# new file: usr/share/rear/output/default/20_make_prefix_dir.sh | |
# new file: usr/share/rear/output/default/25_create_lock.sh | |
# renamed: usr/share/rear/output/NETFS/default/95_copy_result_files.sh -> usr/share/rear/output/default/95_copy_result_files.sh | |
# new file: usr/share/rear/output/default/97_remove_lock.sh | |
# modified: usr/share/rear/prep/NETFS/default/07_set_backup_archive.sh | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment