aspose file tools*
The moose likes Linux / UNIX and the fly likes Incremental filename script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Incremental filename script" Watch "Incremental filename script" New topic
Author

Incremental filename script

Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Hi all,

I currently have a backup cron job running every hour to create a backup
of my code repository. The only issue at the moment is that the backup file
gets over-written each time the job runs.

Is there a way to script the appending of a number onto the file name so
that I can keep say the most recent 50 copies of the file? eg:

backup1.zip
.
.
.
backup50.zip

And when the number hits (say) 50 it'll return to 1?

Many thanks,

Kev
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

I assume that either you're not using a version control system or else that you're really paranoid about your VCS server breaking down. If you're not using some sort of VCS, such as CVS, Subversion or even Visual SourceSafe, consider doing so. I backup my VCS's at 4:00 am every morning as a cron job, but don't keep versions of them - VCS systems are inherently cumulative. About once a week, the backup copies get burned out to DVD as long-term archives. I keep a couple of generations just in case the master VCS gets trashed, the online backup gets trashed and the latest DVD turns out to be unreadable.

I'm pretty paranoid myself.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Tim,

I'm pretty paranoid too! We (will) have a nightly backup job to back up the repository, but I want my own backup jobs to run as well (very paranoid). It's more to do with being able to restore the repository quickly to another server (i.e. myself) rather than have to wait for a full restore by our server admin. I think I've managed to sort it out thought.

Kev
Brian Wright
Greenhorn

Joined: Dec 12, 2005
Posts: 11
Here's a very basic way to do what you're looking for, I think. Note that there are a horde of ways to do this, I was just looking for something fairly easy to follow:

===========================================================
#!/usr/bin/ksh
LATEST=$(ls -1t backup*.zip | head -1 | cut -d. -f1 | sed "s+backup++g")

if [[ ${LATEST} -eq 50 ]]
then
LATEST=0
fi

NEW=$(( ${LATEST} + 1 ))


BACKUP_FILENAME="backup${NEW}.zip"
===============================================================

Hope this gives you something to play with!
 
Don't get me started about those stupid light bulbs.
 
subject: Incremental filename script