-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmove-datfile.sh
More file actions
executable file
·85 lines (66 loc) · 2.44 KB
/
move-datfile.sh
File metadata and controls
executable file
·85 lines (66 loc) · 2.44 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# move-datfile.sh
#
# usage: move-datfile.sh DIRNAME
#
# where DIRNAME is the name of a directory containing .dat files. This script will generate an
# empty directory tree of BACKUPDIR and move the dat files in DIRNAME into it.
#
# Luke Sjulson 2021-09-17 (with contribution from Maurice Volaski)
# examples:
# BACKUPDIR='/home/pi/' # the name of the directory to backup
# NASDIR='/mnt/NAS/lab/dat_files/luke/pi/' # where to backup the directory tree
# note that the pi directory is present in both BACKUPDIR and NASDIR
# include trailing slashes for both directory names
BACKUPDIR='/home/pi/' # the name of the directory to backup
NASDIR='/mnt/NAS/lab/dat_files/luke/pi/' # where to backup the directory tree
MOUNTSTRING='dreadd' # if this string does not show up in the list of mounted drives, the script will abort
FILENAME='DATmove.log' # the name of the logfile
TESTRUN=false # if true, dat files do not get copied, but directory tree is still made
MOVEDATFILES=false # if false, the dat files are copied instead of moved
#######################################################
# no user-editable parameters below this line
#######################################################
# figure out source path
cd $1
SOURCEDIR=$PWD
echo 'Moving DAT files off of workstation, starting' `date` | tee -a $FILENAME
echo TESTRUN = $TESTRUN | tee -a $FILENAME
echo MOVEDATFILES = $MOVEDATFILES | tee -a $FILENAME
echo sourcedir: $SOURCEDIR | tee -a $FILENAME
# figure out middle part of path
BACKUPDIR2=$(echo $BACKUPDIR | sed 's/\//\\\//g')
#echo backupdir2:
#echo $BACKUPDIR2
MIDPART=$(echo $PWD | sed "s/$BACKUPDIR2//")
#echo midpart:
#echo $MIDPART
# figure out destination path
DESTDIR=$NASDIR/$MIDPART
echo destdir: $DESTDIR | tee -a $FILENAME
# set test flag for rsync
if [ $TESTRUN = true ] ; then
TESTFLAG='-n'
else
TESTFLAG=''
fi
# set move flag for rsync (as opposed to copy)
if [ $MOVEDATFILES = true ] ; then
MOVEFLAG='--remove-source-files'
else
MOVEFLAG=''
fi
# run rsync
/usr/bin/df | /usr/bin/grep $MOUNTSTRING # check if the NAS is mounted
if [ ${?} -eq 0 ] ; then
# make empty copy of entire directory tree
/usr/bin/rsync -v -a --progress \
--include='*/' --exclude='*' --no-perms --no-owner --stats \
$BACKUPDIR $NASDIR | tee -a $FILENAME
# use rsync to move .dat files
rsync -vv $MOVEFLAG $TESTFLAG $SOURCEDIR/*.dat $DESTDIR | tee -a $FILENAME
else
echo
echo ERROR - $MOUNTSTRING NOT FOUND! | tee -a $FILENAME
echo
fi