-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_data.sh
executable file
·48 lines (33 loc) · 1.37 KB
/
package_data.sh
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
#!/bin/bash
if [ $# -lt 2 ]
then
echo """
This script packages data into a tarball for storage on tape. It will
generate:
- A tarball containing everything from the input folder
- A .ncdu file of the input folder
- A .sha512 file containing hashes for each item in the input folder
- A .tar.sha512 file containing a hash of the tarball itself
Quotes and spaces will be removed from files and folders. The input folder name
should be prefixed with the date to conform to our format. All outputs will use
the same name as the input folder.
Usage:
package_data.sh <in_dir> <out_dir>
"""
exit 2
fi
in_dir=$1
out_dir=$2
cd ${in_dir}
# Remove quotations and spaces from file names
find . '(' -name "*\"*" -o -name "*\'*" -o -name "* *" ')' -exec bash -c $'for f; do echo "Fixing malformed file name ${f}"; mv "$f" "${f//[\\\047\\\042\\\040]/}"; done' _ {} +
# Set the destination path for output files
fname=$(basename $in_dir)
out_path=${out_dir}/${fname}
# Generate an ncdu file for the input folder
ncdu -x -o ${out_path}.ncdu ./
# tar and hash input folder
tar --format=posix -cvpWf ${out_path}.tar * | grep -v -e ^Verify -e /$ | xargs -I '{}' sh -c "test -f '{}' && sha512sum --tag '{}'" >> ${out_path}.sha512
# Hash whole tarball as well, allows faster verification of copies
cd ${out_dir}
sha512sum --tag ./$(basename ${out_path}).tar >> ${out_path}.tar.sha512