Skip to content

Instantly share code, notes, and snippets.

@for2ando
Created July 11, 2017 11:18
Show Gist options
  • Save for2ando/dd63b4e406aa150734587455953e7e3c to your computer and use it in GitHub Desktop.
Save for2ando/dd63b4e406aa150734587455953e7e3c to your computer and use it in GitHub Desktop.
A shell script for backup and then make lists of backup files and write the list to files in source directories.
#!/bin/bash
LIST_FILE_NAME='BKLIST.txt'
LIST_CMD='ls -l -R'
pname=$(basename "$0")
usage="$pname [-ls DirGlobToMakeListFile] SourceDir DestDir
OPTIONS
SourceDir
A source directory of copying (not a miroring)
DestDir
A destination directory of copying
-ls DirGlobToMakeListFile
Make list of directories descendants of the destination directory,
and save this list to correspodent directories descendants of the source
directory.
The argument is a shell glob pattern for directories to be listed and
to which save the list."
while true; do
case "$1" in
-ls|--ls) shift; listglob="$1"; shift;;
-*) shift;;
*) break;;
esac
done
test $# -le 1 && { echo "$usage"; exit 0; }
makelist() {
src="$1"
dst="$2"
listglob="$3"
for dir in $(cd "$dst"; echo $listglob); do
test -d "$dst/$dir" || continue
test -d "$src/$dir" && $LIST_CMD "$dst/$dir" >"$src/$dir/$LIST_FILE_NAME"
done
}
robocp "$1" "$2"
test -n "$listglob" && makelist "$1" "$2" "$listglob"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment