sync-view.sh: fix TARGETDIR variable name, missing '/' when ROOTDIR=/
This commit is contained in:
@@ -32,14 +32,13 @@
|
|||||||
# local.
|
# local.
|
||||||
#
|
#
|
||||||
# -c, --config
|
# -c, --config
|
||||||
# A sync.sh file where
|
# A sync.sh configuration file where the script could find variables
|
||||||
# if non-existant. By default, a temporary directory will be created
|
# SOURCEDIR (option '-r') and BACKUPDIR (option '-b').
|
||||||
# in /tmp.
|
|
||||||
#
|
#
|
||||||
# -d, --destdir
|
# -d, --destdir
|
||||||
# Directory which will hold links to actual files. It will be created
|
# Directory which will hold links to actual files. It will be created
|
||||||
# if non-existant. By default, a temporary directory will be created
|
# if non-existant. If this option is missing, a temporary directory will
|
||||||
# in /tmp.
|
# be created in /tmp.
|
||||||
#
|
#
|
||||||
# -h, --help
|
# -h, --help
|
||||||
# Display short help and exit.
|
# Display short help and exit.
|
||||||
@@ -225,21 +224,16 @@ parse_opts() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
check_dirs() {
|
check_paths() {
|
||||||
local dir tmp
|
local dir tmp
|
||||||
|
|
||||||
log "ROOTDIR=[%s]" "$ROOTDIR"
|
|
||||||
log "BACKUPDIR=[%s]" "$BACKUPDIR"
|
|
||||||
log "TARGETDIR=[%s]" "$TARGETDIR"
|
|
||||||
log "FILE=[%s]" "$TARGET"
|
|
||||||
|
|
||||||
[[ -z "$BACKUPDIR" ]] && printf "%s: backup directory is not set.\n" "$CMDNAME" && \
|
[[ -z "$BACKUPDIR" ]] && printf "%s: backup directory is not set.\n" "$CMDNAME" && \
|
||||||
! usage
|
! usage
|
||||||
[[ -z "$ROOTDIR" ]] && printf "%s: source directory is not set.\n" "$CMDNAME" && \
|
[[ -z "$ROOTDIR" ]] && printf "%s: source directory is not set.\n" "$CMDNAME" && \
|
||||||
! usage
|
! usage
|
||||||
if [[ -n "$TARGETDIR" ]]; then
|
if [[ -n "$TARGETDIR" ]]; then
|
||||||
if [[ ! -e $TARGETDIR ]]; then
|
if [[ ! -e $TARGETDIR ]]; then
|
||||||
log "Creating destination directory %s." "$DESTDIR"
|
log "Creating destination directory %s." "$TARGETDIR"
|
||||||
mkdir "$TARGETDIR"
|
mkdir "$TARGETDIR"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@@ -255,20 +249,25 @@ check_dirs() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if ! pushd "$TARGETDIR" > /dev/null; then
|
if ! pushd "$TARGETDIR" > /dev/null; then
|
||||||
printf "cannot change to directory %s.\n" "$DESTDIR"
|
printf "cannot change to directory %s.\n" "$TARGETDIR"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# remove existing files
|
# remove existing files
|
||||||
if [[ -n "$(ls -A .)" ]]; then
|
if [[ -n "$(ls -A .)" ]]; then
|
||||||
log "Cleaning existing directory %s." "$DESTDIR"
|
log "Cleaning existing directory %s." "$TARGETDIR"
|
||||||
for target in *; do
|
for target in *; do
|
||||||
rm "$target"
|
rm "$target"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
log "ROOTDIR=[%s]" "$ROOTDIR"
|
||||||
|
log "BACKUPDIR=[%s]" "$BACKUPDIR"
|
||||||
|
log "TARGETDIR=[%s]" "$TARGETDIR"
|
||||||
|
log "FILE=[%s]" "$TARGET"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_opts "$@"
|
parse_opts "$@"
|
||||||
check_dirs
|
check_paths
|
||||||
|
|
||||||
# add missing directories
|
# add missing directories
|
||||||
declare -a DIRS
|
declare -a DIRS
|
||||||
@@ -277,7 +276,9 @@ log "DIRS=%s" "${DIRS[*]}"
|
|||||||
|
|
||||||
for file in "${DIRS[@]}"; do
|
for file in "${DIRS[@]}"; do
|
||||||
# src is file/dir in backup tree
|
# src is file/dir in backup tree
|
||||||
src="$file${TARGET#"$ROOTDIR"}"
|
_tmp=${TARGET#"$ROOTDIR"}
|
||||||
|
[[ $_tmp =~ ^/.*$ ]] || _tmp="/$_tmp"
|
||||||
|
src="$file$_tmp"
|
||||||
if [[ ! -e $src ]]; then
|
if [[ ! -e $src ]]; then
|
||||||
log "Skipping non-existing %s" "$src"
|
log "Skipping non-existing %s" "$src"
|
||||||
continue
|
continue
|
||||||
@@ -305,7 +306,7 @@ for file in "${DIRS[@]}"; do
|
|||||||
INODES[$inode]=${INODES[$inode]:-$date}
|
INODES[$inode]=${INODES[$inode]:-$date}
|
||||||
done
|
done
|
||||||
|
|
||||||
{
|
if [[ -n "$(ls -A .)" ]]; then
|
||||||
printf "mod time|backup|inode|size|perms|path\n"
|
printf "mod time|backup|inode|size|perms|path\n"
|
||||||
# for file in {dai,week,month,year}ly-[0-9][0-9]; do
|
# for file in {dai,week,month,year}ly-[0-9][0-9]; do
|
||||||
for file in *; do
|
for file in *; do
|
||||||
@@ -317,6 +318,7 @@ done
|
|||||||
printf "%s|%s|%s|%s|%s|%s\n" "$date" "$file" "$inode" "$size" "$perms" "$path"
|
printf "%s|%s|%s|%s|%s|%s\n" "$date" "$file" "$inode" "$size" "$perms" "$path"
|
||||||
# ls -lrt "$TARGETDIR"
|
# ls -lrt "$TARGETDIR"
|
||||||
done | sort -r
|
done | sort -r
|
||||||
} | column -t -s\|
|
fi | column -t -s\|
|
||||||
|
|
||||||
|
printf "temporary files directory is: %s\n" "$PWD"
|
||||||
exit 0
|
exit 0
|
||||||
|
Reference in New Issue
Block a user