forked from amiaopensource/ltopers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwritelto
executable file
·132 lines (108 loc) · 4.35 KB
/
writelto
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
# writelto
# This script writes the contents of a specified directory onto a mounted
# LTFS-formated LTO tape.
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
DEPENDENCIES=(gcp)
TAPE_MOUNT_POINT="/mnt"
TAPE_SERIAL_REGEX="^[A-Z0-9]{6}$"
unset HIDDEN_FILES
TAPE_EJECT="N" # don't eject tape
_check_for_lto_index_dir
LTO_LOGS="${LTO_INDEX_DIR}"
unset VERSION
if [[ $(dirname $(command -v "${0}")) = "/usr/local/bin" || $(dirname $(command -v "${0}")) = "${HOME}/.linuxbrew/bin" ]] ; then
VERSION=$(TMP=$(brew info ltopers | grep ".*\*$" | grep -Eo "/ltopers/.* \(") ; echo "${TMP:9:(${#TMP}-11)}")
fi
# no .DS_Store onto external storage
if [[ "$(uname -s)" = "Darwin" ]] ; then
if [[ "$(defaults read com.apple.desktopservices DSDontWriteNetworkStores 2>/dev/null)" != "true" ]] ; then
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
fi
fi
_usage(){
cat <<EOF
$(basename "${0}") ${VERSION}
This script writes the contents of a specified directory onto a mounted
LTFS-formated LTO tape.
Dependencies: ${DEPENDENCIES[@]}
Usage: $(basename "${0}") -t [-e] [-v] | -h
-t tape serial
-e state yes (Y) or no (N) to ejecting the tape after write, default
is yes
-v reads back and creates checksums for the contents of a tape, and
writes checksums to a file named with the tape name and date,
located in the LTO logs directory
-x use barcode label as tape serial (caveat: this is not standard)
-h display this help
EOF
}
OPTIND=1
while getopts ":t:e:vxh" opt ; do
case "${opt}" in
t) TAPE_SERIAL="${OPTARG}" ;;
e) TAPE_EJECT="${OPTARG}" ;;
v) VERIFY="Y" ;;
x) TAPE_SERIAL_REGEX="^[A-Z0-9]{6}(L[5-8]|M8)$" ;;
h) _usage ; exit 0 ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
SOURCE_DIR="${1}"
if [[ ! "${TAPE_SERIAL}" ]] ; then
_report -qn "Enter the LTO tape barcode: "
read -e TAPE_SERIAL
fi
if [[ ! "${SOURCE_DIR}" ]] ; then
_report -qn "Drag in the directory to write to tape: "
read -e SOURCE_DIR
fi
if [[ ! $(echo "${TAPE_SERIAL}" | grep -E "${TAPE_SERIAL_REGEX}") ]] ; then
_report -w "Tape serial ${TAPE_SERIAL} is not valid."
_report -w "Proceeding with non-standard Tape Serial"
fi
# Check for colons in filenames of source directory.
_check_for_colons "${SOURCE_DIR}"
TAPE_PATH="${TAPE_MOUNT_POINT}/${TAPE_SERIAL}"
_checkdir "${SOURCE_DIR}"
# remove .DS_Store files
find "${SOURCE_DIR}/" -name '.DS_Store' -type f -delete
if [ -f "${SOURCE_DIR}"/tapechecksum.md5 ] ; then
db_fixity=$(cat "${SOURCE_DIR}"/tapechecksum.md5)
fi
_checkdir "${TAPE_PATH}"
gcp --preserve=mode,timestamps -nRv "${SOURCE_DIR}" "${TAPE_PATH}"
"${SCRIPTDIR}/migratefiles" -o "${TAPE_PATH}/$(basename -- ${SOURCE_DIR})" "${SOURCE_DIR}/"
RSYNC_ERR_1="$?"
WRITELTODIR="${LTO_LOGS}/writelto"
_mkdir2 "${WRITELTODIR}"
if [ -n "$RSYNC_ERR_2" ] ; then
echo "rsync exited with ${RSYNC_ERR_1} on the first pass" | tee -a "${WRITELTODIR}/${TAPE_SERIAL}_writelto.txt" 2>&1
else
echo "rsync exited with ${RSYNC_ERR_1}." | tee -a "${WRITELTODIR}/${TAPE_SERIAL}_writelto.txt" 2>&1
fi
_check_for_lto_md5_flags
READBACKOUTPUT=""
if [[ "${VERIFY}" = "Y" ]] ; then
VERIFYTIME=$(_get_iso8601_c)
READBACKDIR="${LTO_LOGS}/readback_checksums"
_mkdir2 "${READBACKDIR}"
find "${TAPE_PATH}" -type f ! -name .DS_Store -exec $LTO_MD5_FLAGS "{}" >> "${READBACKDIR}/${TAPE_SERIAL}_ReadBack_checksum_${VERIFYTIME}.md5" \;
READBACKOUTPUT="${READBACKDIR}/${TAPE_SERIAL}_ReadBack_checksum_${VERIFYTIME}.md5"
sort -k 2 -o "${READBACKOUTPUT}" "${READBACKOUTPUT}"
printf "\nreadback checksums written to:\n\t%s" "${READBACKOUTPUT}"
#TODO: update in upstream
fi
echo -n "$(date +%FT%T) " >> "${LTO_LOGS}/tape_capacity.txt"
echo $(df -Ph "${TAPE_PATH}" | tail -n 1) >> "${LTO_LOGS}/tape_capacity.txt"
./renameschemas -u
SCHEMA_FILE="${LTO_LOGS}/schema/${TAPE_SERIAL}.schema"
printf "\nrsync error report written to:\n\t%s/%s_writelto.txt" "${WRITELTODIR}" "${TAPE_SERIAL}"
printf "\nafter ejecting tape, lto schema file written to:\n\t%s\n\n" "${SCHEMA_FILE}"
case "${TAPE_EJECT}" in
y|Y) umount "${TAPE_PATH}" ;;
*) echo "Done writing but not ejecting ${TAPE_SERIAL}." ;;
esac