63 lines
1.6 KiB
Bash
Executable File
63 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -e
|
|
#set -v
|
|
|
|
LIVE_SNIPPET_DIR=/opt/aus2/incoming/3
|
|
BACKUP_DIR=/opt/aus2/snippets/backup
|
|
STAGING_DIR=/opt/aus2/snippets/staging
|
|
|
|
WC=/usr/bin/wc
|
|
DATE=/bin/date
|
|
TAR=/bin/tar
|
|
SED=/bin/sed
|
|
GREP=/bin/grep
|
|
|
|
if test -z $1; then
|
|
echo Usage: $0 [snippet-directory-to-sync-in from $STAGING_DIR]
|
|
exit 1
|
|
fi
|
|
|
|
newSnippetDir=`echo $1 | $SED -e 's/\///'g`
|
|
|
|
if ! test -d $STAGING_DIR/$newSnippetDir; then
|
|
echo Usage: $0 [snippet-directory-to-sync-in from $STAGING_DIR]
|
|
exit 1
|
|
fi
|
|
|
|
currentDate=`$DATE +%Y%m%d`
|
|
|
|
## We use the shell's expansion capabilites to get a list of other snippet
|
|
## directories we may have pushed today... kinda lame, but it works.
|
|
|
|
pushd $BACKUP_DIR > /dev/null
|
|
preDirCount=`echo $currentDate-?-pre-* | $GREP -v \? | $WC -w`
|
|
popd > /dev/null
|
|
|
|
## Increment the count by one, for the new snippet backup directory we're
|
|
## about to create
|
|
let nextPreDirCount=$preDirCount+1
|
|
#echo $nextPreDirCount
|
|
backupDirName=$currentDate-$nextPreDirCount-pre-$1
|
|
|
|
### Find list of directories that change
|
|
absNewSnippetDir=$STAGING_DIR/$newSnippetDir
|
|
changedDirs=$(find $absNewSnippetDir -maxdepth 3 -mindepth 3 -type d | $SED s,$absNewSnippetDir/,,g)
|
|
args=""
|
|
### Skip directories that don't exist in the live snippets directory
|
|
### no need to back them up, since they don't exist yet!
|
|
for d in $changedDirs; do
|
|
if [ ! -d $LIVE_SNIPPET_DIR/$d ]; then
|
|
echo Ignoring $d
|
|
else
|
|
args="$args $d"
|
|
fi
|
|
done
|
|
|
|
pushd $LIVE_SNIPPET_DIR > /dev/null
|
|
echo Running time $TAR cfvz $BACKUP_DIR/$backupDirName.tar.gz $args
|
|
time $TAR cfvz $BACKUP_DIR/$backupDirName.tar.gz $args
|
|
popd > /dev/null
|
|
|
|
exit 0
|