[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash commands

Bob Proulx wrote:
> Russell <rjshaw@iprimus.com.au> [2002-09-02 11:42:45 +1000]:
> > Thanks for the tips. I'm getting better;)
> > I've been making this backup script which
> > is nearly complete:
> I am going to leave the full quoted script so that I can comment on
> the parts I want to comment upon...
> You might consider using 'rsync' here.  Especially since this is a
> backup you will be doing the backup when probably nothing has changed.

I'd forgotten about rsync. Just installing it now. It seems to have
all the things i was looking for, including copying directories without
the contents, copying devices, excluding certain patterns etc. Another
poster mentioned it a week or two ago.

> But the 'cp' will always copy all of the files regardless.  Putting an
> rsync here instead will only copy what has changed.

With cp -u, the files are only updated if they're newer.

> Also, as a backup what happens when you remove a file from your
> working directory?  Will the copy _ever_ be removed from backup?  This
> depends upon what you want.  If you were writing to a new CD each time
> it would not be a question.  But if you are keeping a backup on disk
> somewhere then you probably want to delete it from disk eventually.
> What I do is to have rsync rotate me older copies.  I will include an
> example at the bottom.

I forgot about removing obsolete files. I just wanted to save
everything before i crashed and burned;)

> > # Copy everything on main partition
> > # Strip some top level directories we don't want to copy
> > FILES=$( ls / | sed -e s/boot//g | sed -e s/cdrom//g | sed -e s/proc//g | sed -e s/floppy//g | sed -e s/mnt//g | sed -e s/dev//g)
> That sed is pretty clever.  But extremely unwieldy.  To do exactly
> what you are doing easier I would use 'grep -v -e pat1 -e pat2'.  Try
> that and add it to your toolbox of shell scripting.

I didn't realize you could have multiple edits in the one sed command.
I'll remember that.

> But even better is to avoid that entirely.  I can think of two
> different ways of doing that.  Perhaps you will like the grep way
> better but just for the sake of discussion I am going to post another
> method.
> > OPTS="-auv"
> > for i in $FILES
> > do
> >   echo "Updating /$i"
> >   if ! chroot / cp $OPTS $i /mnt
> What does the chroot do for you here?  I don't think you want this.

It's because the ls outputs all the files and directories without a
leading "/". The other way was to add the "/" separately.
> >   then
> >     echo "Failed to update /$i"
> >     exit 1
> >   fi
> > done
> >
> > echo "System backup successful"
> > exit 0
> How about this?  I had to do some on the fly translations.  I
> undoubtedly made some errors which you will have to debug.  Don't use
> this with out approaching it as a task to debug.  But this is my
> normal method to backup my system.  I usually go from one host to a
> different backup host but the concept is the same.
> # This is the destination of the backup.
> DESTDIR=/mnt/backup
> # For rotating incrementals use the three letter day name.
> BACKUPDIR=incr-$(date '+%Y-%m-%d')
> OPTS="-a --delete --numeric-ids --backup --backup-dir=$DESTDIR/$BACKUPDIR"
> for i in $FILES

I assume there's an ls command somewhere that defines FILES.

> do
>   case "$i" in...

Thanks for the script. I'll do some fixing on mine;)

Reply to: