Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPT] SVNBACKUP.sh
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
likewhoa
l33t
l33t


Joined: 04 Oct 2006
Posts: 731
Location: Brooklyn, New York

PostPosted: Thu Feb 01, 2007 7:31 pm    Post subject: [SCRIPT] SVNBACKUP.sh Reply with quote

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..

  1. 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
  2. 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
View user's profile Send private message
Zillode
n00b
n00b


Joined: 19 May 2006
Posts: 54

PostPosted: Fri Feb 02, 2007 6:31 pm    Post subject: Reply with quote

cool thanks
Back to top
View user's profile Send private message
Juha
n00b
n00b


Joined: 09 Feb 2004
Posts: 36
Location: Finland

PostPosted: Sun Feb 04, 2007 12:49 am    Post subject: Reply with quote

Thanks, very useful
_________________
-Juha-
Back to top
View user's profile Send private message
likewhoa
l33t
l33t


Joined: 04 Oct 2006
Posts: 731
Location: Brooklyn, New York

PostPosted: Wed Sep 19, 2007 9:34 am    Post subject: Reply with quote

minor script change. and bumpage.
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2161
Location: The Peanut Gallery

PostPosted: Wed Sep 19, 2007 10:32 am    Post subject: Re: [SCRIPT] SVNBACKUP.sh Reply with quote

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
View user's profile Send private message
likewhoa
l33t
l33t


Joined: 04 Oct 2006
Posts: 731
Location: Brooklyn, New York

PostPosted: Thu Sep 20, 2007 2:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum