View previous topic :: View next topic |
Author |
Message |
likewhoa l33t
Joined: 04 Oct 2006 Posts: 778 Location: Brooklyn, New York
|
Posted: Thu Feb 01, 2007 7:31 pm Post subject: [SCRIPT] SVNBACKUP.sh |
|
|
since I run alot of subversion repositories i decide to make a script that will dump each repo then copy it to a destination, and keep only backups _not_ older than 7 days old. you will need to edit a few variables to make this work for you.
Quote: |
${repos }& ${dest} variables.
|
the way the script works is..
- It begins by going through each repository then it dumps them to your $dest directory using 'svnadmin dump' then it labels them with repository name and current date.
i.e gentoo-20070201
- next it deletes old backups to make room for new, if you wish to keep backups older than 7 days you will need to edit the $deleted variable where +7 means older than 7 days.
well that's it, hope this comes in handy. to load repo dumps use Code: | svnadmin load /path/to/repo < <(bunzip -c repo-20070919.bz2) |
repo-20070919 being the dump file.
Code: |
#!/bin/bash
#Vars
repos="/var/svn"
dest="/mnt/backup_svn"
today=$(date +%Y%d%m)
echo "Starting repo backups/cleanups."
cd ${repos}
while read repo
do
svnadmin dump ${repos}/${repo} |bzip >${dest}/${repo}-${today}.bz2
done < <(find . -mindepth 1 -maxdepth 1 -type d -wholename "./conf" -prune -o -printf '%f\n')
echo "Done doing backups, performing clean ups"
cd ${dest}
find . -type f -mtime +7 -exec rm -v '{}' \;
echo "Clean up done. All done."
|
Last edited by likewhoa on Thu Sep 20, 2007 2:17 pm; edited 6 times in total |
|
Back to top |
|
|
Zillode n00b
Joined: 19 May 2006 Posts: 54
|
Posted: Fri Feb 02, 2007 6:31 pm Post subject: |
|
|
cool thanks |
|
Back to top |
|
|
Juha n00b
Joined: 09 Feb 2004 Posts: 36 Location: Finland
|
Posted: Sun Feb 04, 2007 12:49 am Post subject: |
|
|
Thanks, very useful _________________ -Juha- |
|
Back to top |
|
|
likewhoa l33t
Joined: 04 Oct 2006 Posts: 778 Location: Brooklyn, New York
|
Posted: Wed Sep 19, 2007 9:34 am Post subject: |
|
|
minor script change. and bumpage. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed Sep 19, 2007 10:32 am Post subject: Re: [SCRIPT] SVNBACKUP.sh |
|
|
Hey likewhoa,
This is a bit safer (directories with spaces -- see /msg greybot quotes) and quicker (only runs date once; cf http://wooledge.org/mywiki/UsingFind) but there's still a concern I have (see below.)
Code: |
#!/bin/bash
repos="/var/svn"
dest="/mnt/backup_svn"
echo "starting repo backups/cleanups"
cd "$repos"
today="$(date +%Y%d%m)"
while read repo
do
svnadmin dump "$repos/$repo" >"$dest/$repo-$today"
done < <(find . -mindepth 1 -maxdepth 1 -type d -wholename "./conf" -prune -o -print)
echo "done doing backups, performing clean ups"
cd "$dest"
find . -type f -mtime +7 -exec rm -v '{}' +
echo "clean up done"
|
That last find is going to find all files, not just in top-level, so it was not a count of repos but of files. I hope that's what you were after? I can imagine having svn files that are older; also many of us run with noatime, so I changed it to mtime; change it back if you prefer.
One small point; the find won't cope with files with newlines in the name. The find doc tells you how to deal with that.
HTH. |
|
Back to top |
|
|
likewhoa l33t
Joined: 04 Oct 2006 Posts: 778 Location: Brooklyn, New York
|
Posted: Thu Sep 20, 2007 2:01 pm Post subject: |
|
|
updated the script to include steveL's changes.
I also added a pipe to bzip2 for compression. extraction can be done with bunzip.
thanks steveL for the addon |
|
Back to top |
|
|
|