forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migratefiles
executable file
·49 lines (43 loc) · 1.69 KB
/
migratefiles
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#microservice for moving files during migration, uses rsync to move files and write log, have to format to have source and target locations
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
_usage(){
echo "This script moves files from one location to another."
echo " -o directory ( directory to write the resulting file to )"
echo " -r option to remove source files upon transfer"
echo "the structure of the script is as follows: migratefiles -o ${TARGET} ${INPUT}, note that this is different than rsync commands"
}
user_input="${*}"
OPTIND=1
while getopts ":o:l:r" OPT ; do
case "${OPT}" in
o) OUTPUTDIR_FORCED="${OPTARG}" ;;
r) REMOVESOURCEFILES="Y" ;;
l) LOGFILE="${OPTARG}" ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
TARGET="${OUTPUTDIR_FORCED}/"
DATE=$(_get_iso8601_c)
while [ "${*}" != "" ] ; do
INPUT="${1}"
_report_to_db
echo "The input is: ${INPUT}"
echo "The target is: ${TARGET}"
if [ "${INPUT}/" == "${TARGET}" ] ; then
echo "Due to the Target location and the Input location being the same, files will not be migrated."
exit 0
fi
shift
if [ -z "${LOGFILE}" ] ; then
LOGFILE="${HOME}/migrate.log"
fi
if [ "${REMOVESOURCEFILES}" == "Y" ] ; then
EXTRAOUTPUTS+=(--remove-source-files)
fi
_run_critical_event rsync -rtvPih "${EXTRAOUTPUTS[@]}" --log-file="${LOGFILE}" --log-file-format="${DATE} '%f' %l '${TARGET}'" "${INPUT}" "${TARGET}"
_eventoutcome_update
done