-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreeze.zsh
More file actions
executable file
·64 lines (49 loc) · 1.74 KB
/
freeze.zsh
File metadata and controls
executable file
·64 lines (49 loc) · 1.74 KB
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
#!/usr/bin/zsh
# compress each folder at a given level in a hierarchy to a .tar.xz, in parallel
# usage freeze.zsh <hotpath> <coldpath> <tmppath> <folder> <level>
# e.g. nohup ./freeze.zsh /groups/genie/genie /nearline/genie /nrs/genie 20180228_ArcLight96f 1 &
# nohup ./freeze.zsh /groups/genie/genie/GECIScreenData/GECI_Imaging_Data/SCaMP /nearline/genie/SCaMP2 /nrs/genie/arthurb/tar.xz 20250324_SCaMP_raw 1 &!
set -o errexit
if [[ $# != '5' ]] ; then
echo wrong number of input arguments
exit
fi
hotpath=$1
coldpath=$2
tmppath=$3
folder=$4
level=$5
set -o xtrace
[[ -z $(find $hotpath/$folder -type f ! -writable) ]] || ( echo ERROR: not all files are writeable ; return 1 )
IFS=$'\n'
doit() {
mkdir -p $coldpath/$(dirname $1)
XZ_OPT=-1 tar cJf $coldpath/${1}.tar.xz -C $(dirname $1) $(basename $1)
filesizes=$(du -s --bytes $coldpath/${1}.tar.xz $1 | cut -f1)
echo compression ratio = $(dc -e "3 k $filesizes / p") for $1
sync
mkdir -p $tmppath/$(dirname $1)
tar xf $coldpath/${1}.tar.xz -C $tmppath/$(dirname $1)
if diff -r --no-dereference $1 $tmppath/$1; then
rm -rf $1
chmod ug+w -R $tmppath/$1
rm -rf $tmppath/$1
fi
}
cd $hotpath
ls -R $folder > $folder/toc.txt
pids=()
for subfolder in $(find $folder -mindepth $level -maxdepth $level -type d) ; do
doit $subfolder &
pids+=($!)
done
for file in $(find $folder -maxdepth $level -type f) ; do
doit $file &
pids+=($!)
done
for pid in ${pids[@]}; do
wait $pid || return 1
done
[[ -d $tmppath/$folder ]] && find $tmppath/$folder -depth -type d -exec rmdir \{\} \;
[[ -d $hotpath/$folder ]] && find $hotpath/$folder -depth -type d -exec rmdir \{\} \;
[[ $? ]] && touch $hotpath/${folder}-MOVED-TO-NEARLINE