Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shell script running in AIX that will do the backup for each SVN repository every night. The execution is as follow:

Download the each repository save as a dump file:

svnrdump on repo_A

svnrdump on repo_B

svnrdump on repo_X ## X is the subsequent number of repository

After this download process complete, the content will be zipped:

bzip2 --compress repo_A_yyyymmdd.dump

bzip2 --compress repo_B_yyyymmdd.dump

bzip2 --compress repo_X_yyyymmdd.dump ## X is the subsequent number of backup copy

Then I will do a housekeeping on the backup copies by removing those copy that is longer than 5th day old from today (I only need to keep the last 5 latest backup copies):

rm `ls -t repo_A_????????.dump.bz2 | tail -n +6`

rm `ls -t repo_B_????????.dump.bz2 | tail -n +6`

rm `ls -t repo_X_????????.dump.bz2 | tail -n +6` ## X is the subsequent number of backup copy

My question

Is there a way to optimize this code by putting those repo name into an array and then execute every command for each repo in a loop?

share|improve this question
up vote 1 down vote accepted

Or alternatively:

for repo in repo_A repo_B repo_X; do
   svnadmin dump $repodir/$repo | bzip2 -9 > $backupdir/$repo-`date +%F`.dump.bz2
find /$backupdir -type f -iname *dump.bz2 -mtime +$maxagedays -exec rm -f {} \;
share|improve this answer
I like this answer because the code looks clean. – huahsin68 Apr 17 '13 at 7:02

Try something like this:

First form, array of suffixes:


array=(A B C D E F)
for i in "${array[@]}"
    echo svnrdump on repo_$i
    echo bzip2 --compress "repo_$i.dump"

Second form, if there repo names are more diverse:


while read REPO; do
    echo svnrdump on  "${REPO}"
    echo bzip2 --compress "${REPO}".dump
done << REPOLIST

You will have to add all repos to the REPOLIST.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.