Files
Mozilla/mozilla/tools/release/bin/backupsnip
nrthomas%gmail.com 4523864dc2 Bug 632841, backupsnip should not bail out because of trailing /, r=rail
git-svn-id: svn://10.0.0.236/trunk@263537 18797224-902f-48f8-a5cc-f745e15eee43
2012-03-08 21:30:25 +00:00

70 lines
1.9 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-$newSnippetDir
### Find list of directories that change
absNewSnippetDir=$STAGING_DIR/$newSnippetDir
changedDirs=$(find $absNewSnippetDir -maxdepth 4 -mindepth 4 -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
if [ -z "$args" ]; then
echo
echo 'Nothing to backup. There could be something wrong, or you could'
echo 'be creating new directories (eg test snippets for a major update).'
exit 0
fi
pushd $LIVE_SNIPPET_DIR > /dev/null
echo Running /usr/bin/time -p -o $BACKUP_DIR/$backupDirName.time $TAR cfvz $BACKUP_DIR/$backupDirName.tar.gz $args
/usr/bin/time -p -o $BACKUP_DIR/$backupDirName.time $TAR cfvz $BACKUP_DIR/$backupDirName.tar.gz $args
popd > /dev/null
exit 0