Warning this article may contain opinions of the author that you and iTWire don't agree with.
Visit the last page to have your say in our forum.

No. 1 Story

Telstra adds one million mobile services, but Sensis plummets

Telstra has revealed the addition of almost one million new mobile services in the six months to December 2011, but Sensis revenues plummeted 24 percent in 12 months.

read more

The Road to Ubuntu - Backup Salvation

Opinion and Analysis

I want to keep multiple copies of my backup folder, say every 10 minutes for 48 hours, so I can dip back into previous versions in case I want to recover something I deleted. I know this sounds like overkill but it's a luxury I had when I worked in a newspaper office, and now that I work for myself I don't want to give it up.

I discovered I could keep multiple versions by renaming the folders like this;

mv ${des}/3 ${des}/4
mv ${des}/2 ${des}/3

mv ${des}/1 ${des}/2


Folder number 1 becomes 2, 2 becomes 3 and so on. While this worked, it's not very practical if you want to keep hundreds of folders. I did a lot of basic programming on a Commodore 64 as a kid, so I've got an idea of how programs work even if I don't know all of the commands and syntax to use with Ubuntu. I knew I needed a loop and, after a few Google searches, I came up with this;

# Number of copies to keep
count=5


# delete oldest folder

rm -rf ${des}/${count}


# stop loop when count is not greater than 1

while [ $count -gt 1 ]   


# loop to rename folders

do

old=`expr $count - 1`

mv ${des}/${old} ${des}/${count}

count=`expr $count - 1`

done


It might not look like much, but it did the trick and I was pretty pleased with myself. The problem is I wanted timestamped folders, but I couldn't figure out how to renumber the folders while retaining the timestamp in the name. I took another approach, looking for a way to delete folders according to their age, and found this on howtogeek which deletes folders more than 5 days old;

find /path/to/files* -mtime +5 -exec rm {} \;

Adapting my script, I came up with;

# Source
sou="/windows/data/Documents and Settings/Adam/My Documents/Adam/Work/AAA In Progress"


# Destination
des="/windows/Public/ubuntubackup"


# Number of days to keep files

days=5


now=$(date +%y-%m-%d_%H:%M)

mkdir ${des}/${now}

cp "${sou}"/* ${des}/${now}

find ${des}/* -mtime +${days} -exec rm {} \;


It seemed to work perfectly, but then things went screwy and the folders a being renamed with temp names like 0N47VU~S on the network drive rather than timestamps. Any suggestions would be greatly appreciated, but meanwhile at least my numbered folder system works.

With my local backup needs taken care of, it was time to turn my attention to FTP. CONTINUED



- sponsored feature -

The Death of Traditional BI: What’s Next?

How to Make Business Discovery Work for Your Business IP PABX BUYING GUIDE

Business Discovery takes its cues from consumer apps. Like Google, it encourages us- ers to hunt for and explore data without worrying about or even noticing the underly- ing technology. Their entire experience is working within an intuitive interface to get real-time, self-service results with only minimal training. ...more