Skip to content

Instantly share code, notes, and snippets.

@imyousuf
Created September 23, 2010 14:14
Show Gist options
  • Save imyousuf/593670 to your computer and use it in GitHub Desktop.
Save imyousuf/593670 to your computer and use it in GitHub Desktop.
#!/bin/sh
HUDSON_WORK_DIR=/home/hudson/.hudson/
BACKUP_DIR=/home/smartadmin/hudson/backup/
files_to_copy=$(find "$HUDSON_WORK_DIR" | grep -v "^\(.*/\(workspace\|builds\|modules\)/.*\)")
(
stamp=$(date +%Y-%m-%d'T'%H:%M:%S%z)
current_bk_dir="$BACKUP_DIR"
mkdir -p "$current_bk_dir"
cd "$current_bk_dir" || exit 1
test -d .git || git init
for file in $files_to_copy
do
if test -d "$file"
then
mkdir -pv ".$(echo $file $HUDSON_WORK_DIR | awk '{ print substr($1, length($2)) }')"
else
cp -rv "$file" .$(echo "$file" "$HUDSON_WORK_DIR" | awk '{ print substr($1, length($2)) }')
fi
done
git add .
git status && git commit -m "Backup of $stamp" -s
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment