Script makes dated backup files

Miscellaneous tools
Message
Author
User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

Script makes dated backup files

#1 Post by jrb »

I started out thinking about backing up my Save files (warysave, lupusave, etc.) and wanted them to be identified by date and time as to when they were backed up so that I can choose which one to use when Puppy boots up.

This means copying them and renaming, i.e. warysaveA.3fs becomes warysave-11-09-22_10.13.3fs.

Once I got started writing a script however I realized that it might be handy for this to work on any file or folder so I set it up that way.

I have placed "mk_dated_backup" on the rox right click "Open With" menu.

Just right click on any file or folder, go to "Open With" and choose "mk_dated_backup". The backup will be created in the same folder as the original and a gxmessage will appear when it is finished.

I have attached dated_backup.pet-0.2

Enjoy, J :D

Notes:
- Anything after the last dot (.) in a filename will be treated as an extension and placed after the date and time in the new filename.
- .pets will not work if you change their file name

Changelog
_____________________________
Version 0.2 (25 Sep 2011)
- Everything after the word "save" in a file name will be replaced with the time and date and the original extension.
- mk_dated_backup has been placed on the rox right click menu for .2fs, .3fs, .4fs, scripts and plain text. For all other files it is still on the OpenWith menu

Here's the new code:

Code: Select all

#!/bin/sh
#Make a dated backup of any file or folder with same extension - jrb 22sep11
#Removal of previous dates on pupsave file - jrb 25sep11

#Notes - .pets will not work if you change their file name
#Anything after the last dot (.) in a filename will be treated as an extension
#and placed after the date and time in the new filename.


FILE=$@
FNAME=`basename $FILE`
FRST=${FNAME%%save*}
LAST=${FNAME##*save}
DIR=`dirname $FILE`
EXT1=${FILE##*.}

#if file has no extension must use the following:
if [ $FILE = $EXT1 ]
	then
		EXT2=""
	else		
		EXT2=.$EXT1
fi

#Everything after the word "save" in a file name will be 
#replaced with the time and date and the original extension.
#This includes any descriptors you may have placed on your save file.
if [ $FRST = $LAST ]
	then
		OLDFILE=`basename $FILE .$EXT1`
	else
		OLDFILE="$FRST"save
fi

NEWFILE="$OLDFILE"-`date +%y-%m-%d_%H.%M`$EXT2

cd $DIR
cp -r $FILE $DIR/$NEWFILE

gxmessage -center -bg orange "Backup finished"
Attachments
dated_backup-0.2.pet
Create dated backups of files and folders
(1.39 KiB) Downloaded 508 times
Last edited by jrb on Sun 25 Sep 2011, 20:51, edited 1 time in total.

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#2 Post by nooby »

Great thanks much appreciated but?
Don't get me wrong now but I got much bashing
when I supported that one could manually do something
similar.

Them told me rightly??? that one need to reboot and boot with pfix=ram before one can do what your script does? Maybe that is built in and me fail to grasp such code? I take a look again
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#3 Post by jrb »

nooby wrote:Them told me rightly??? that one need to reboot and boot with pfix=ram before one can do what your script does?
In theory one should, but I've been doing hot backups of my save files for years and the worst I've got is a message saying "This file doesn't seem to have shut down properly" and a choice to "ignore" or "cancel". When I choose "ignore" it then opens and runs properly, so far anyway :D .

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#4 Post by nooby »

Cool, so why do them get so upset with me :)

Maybe them love to tell me I am wrong. I don't blame them.

They want only the best for Puppy so that is a good thing.

So how do you use that script then. What is it about it that you like?
When is the proper time to do such back ups? Okay directly after one made a change? A new install of a pet or updating Firefox?
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#5 Post by jrb »

nooby wrote:Cool, so why do them get so upset with me :)
Maybe some people just need to get upset? :?
nooby wrote:So how do you use that script then. What is it about it that you like?
When is the proper time to do such back ups? Okay directly after one made a change? A new install of a pet or updating Firefox?
I like to make a backup save file right after I first use a new Puppy (pupsaveA.3fs). This means just start the puppy, get video, internet, etc. working and then reboot and save.

Then BEFORE I make a major addition or change I create a backup file. When I'm working on new scripts or changes in software it's very comforting knowing if I screw up it's just a matter of rebooting and going back to my last backup and I haven't lost anything. With the date and time on them I can tell at a glance which is the most recent.

Also, when I'm developing a new script I like to back up the script file at each change so if the change doesn't work I can go back to a version that does. Here again having the date and time on the backups is very convenient.

I've just created this script this morning, I'm sure I'll think of more uses for it as I go along. :o

Give it a try and see what you think.

Cheers, J

User avatar
faifpuhp
Posts: 97
Joined: Thu 22 Sep 2011, 06:12

#6 Post by faifpuhp »

Neat idea. Is it worth adding a list of md5sums or something?
[url=http://murga-linux.com/puppy/viewtopic.php?p=566477#566477][b]Strawberry is dead[/b][/url][b]![/b]

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#7 Post by jrb »

faifpuhp wrote:Neat idea. Is it worth adding a list of md5sums or something?
Do you mean generate an md5sum with each backup? Could be handy for files that are to be uploaded but otherwise might just be more clutter.

User avatar
faifpuhp
Posts: 97
Joined: Thu 22 Sep 2011, 06:12

#8 Post by faifpuhp »

jrb wrote:Could be handy for files that are to be uploaded but otherwise might just be more clutter.
Yeah, it totally depends on what you had in mind originally. If there's a place for such a list, and it doesn't quadruple the size of everything, it might make sense. Otherwise it could easily be overkill.
[url=http://murga-linux.com/puppy/viewtopic.php?p=566477#566477][b]Strawberry is dead[/b][/url][b]![/b]

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#9 Post by jrb »

I just realized that a backup of a file previously backed up gives the date and time of both backups, i.e. warysave-11-09-11_12.30-11-09-22_15.25.3fs :?

Not a huge problem. I guess when it gets too long I can just manually rename. I'm open to suggestions.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#10 Post by 8-bit »

How does this compare to hotbkp.targz which when unpacked becomes Pupsave-backup.
With it, available space is checked, the date and time are appended to the pupsave name, the pupsave does not have to be unmounted, the destination is selectable, and a file system check is done on the created file.
The file names it creates are fairly long too. An example would be "lupusave-500.2fs.BKP-11.02.18-22.09" which would say the backup was done on YY.MM.DD-HH.MM
That utility was made by 2byte.

User avatar
faifpuhp
Posts: 97
Joined: Thu 22 Sep 2011, 06:12

#11 Post by faifpuhp »

8-bit wrote:The file names it creates are fairly long too. An example would be "lupusave-500.2fs.BKP-11.02.18-22.09" which would say the backup was done on YY.MM.DD-HH.MM
That utility was made by 2byte.
In the case of this thread, an unintended "feature" is the dates in the name "stack" on subsequent reboots. Perhaps 2byte's version accounts for this, but if someone has a trivial way around it, it might still be cool to fix the script in this thread, or maybe 2byte's version can offer a clue as to how.
[url=http://murga-linux.com/puppy/viewtopic.php?p=566477#566477][b]Strawberry is dead[/b][/url][b]![/b]

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#12 Post by jrb »

8-bit wrote:How does this compare to hotbkp.targz which when unpacked becomes Pupsave-backup.
With it, available space is checked, the date and time are appended to the pupsave name, the pupsave does not have to be unmounted, the destination is selectable, and a file system check is done on the created file.
I tried hotbkp when it first came out. My main problem with it was that the backed up save file had to be renamed before it could be used since the file extension, .2fs or .3fs, ended up in the middle of the name.

Took me quite a while to get around to working on a solution and now as I mentioned in the 1st post I like the idea of using it to backup other files as well.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#13 Post by Flash »

Multisession Puppy creates dated session names. Each session it saves on the DVD is named with the date and time it was created. How the Save script does that I have no idea. I just thought you might find it interesting to compare it to your way.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#14 Post by 8-bit »

Ok, you do not like having to rename the backed up files for a restore to a previous backed up pupsave.
So why not automate the process by including a restore pupsave section to your script with ability to specify pupsave backup location.
You would select the backup you wanted to restore, use sed to remove the date-time part of the name and then do an overwrite of the existing pupsave.
If done correctly, you then have automated the process of restoring and also taken care of mulitiple date-time additions to the filename on a backup.

It would make your simple backup script grow a little, but the end result would be nice.
Of course one thing you have not mentioned is that it is a bad idea to replace a mounted pupsave that is on your disk with another while the one you are replacing is in use.

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#15 Post by nooby »

Thanks JRB,

So 8-bit how does 2byte take care of this part?
Of course one thing you have not mentioned is that it is a bad idea to replace a mounted pupsave that is on your disk with another while the one you are replacing is in use.
How does his script know that it is not in use?

And same question. How did Barry know when he did that script for the Multisession? Or maybe that one only does it when it is to shut down?

Could one not then do a faked shut down. One start on it but not follow through? That way one don't have the pupsave in usage but after the backup one make use of it without shutting down.

I know too little.
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#16 Post by 8-bit »

nooby,
2byte does not have a restore option in his script.
With it, you rename the backed up pupsave before copying it back to the correct directory replacing the one that is there.

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#17 Post by 8-bit »

jrb,
I do not know if this would help and it is designed so as to have the backed up pupsave name in the format of "pupsave-520.sfs.BAK.yy.mm.dd.hh.mm"
But I am sure you could adjust it as needed.
I also leave it up to you to change the line that I have an example backed up pupsave name in.
Maybe use =%1.
But here is a short script for you to try.

Code: Select all

#! /bin/bash
PSNAME='pupsave-500-23.2fs.BAK-11.20.02.12.30'
newname=`echo $PSNAME | sed "s/...................$//"`  #That is 19 periods there.
echo PSNAME = $PSNAME
echo newname = $newname
It will take a supplied name and remove all the BAK-date-time stuff and leave you with a clean pupsave file name that can be copied back in on a restore.
Given a little time, I could write a restore script for restoring from a saved backup of pupsave-xxx.2fs.

nooby
Posts: 10369
Joined: Sun 29 Jun 2008, 19:05
Location: SwedenEurope

#18 Post by nooby »

Thanks 8-bit.
That explains it then. One rename it before restore.

TinyCore has a back up and restore function that is already built in.
So would be interesting to get how them do that feature :)

What about this .2fs and .3s some puppies one have .2fs and for some one have .3fs out of habit or curiosity. Would one need two different such scripts then?
I use Google Search on Puppy Forum
not an ideal solution though

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#19 Post by 8-bit »

nooby, if you copy the short script into geany, save it and nake it executable, you can edit the line in geany that defines PSNAME.
Put any pupsave name and type in there replacing the "pupsave-500-23.2fs" with any name you want to try it with such as warysave-2000.3fs or noobysave-01.4fs.
It will still work fine.
The only thing here is that it expects the pupsave backup name to be in a given format.
If the 2fs or 3fs extension is at the end of the name with the date-time stamp in the middle, then you have to change the way it is parsed to get a resulting name without the time-date stamp.
With a little effort, a GUI could be made that supports drag and drop for input of the filename.

User avatar
jrb
Posts: 1536
Joined: Tue 11 Dec 2007, 19:56
Location: Smithers, BC, Canada

#20 Post by jrb »

Flash wrote:Multisession Puppy creates dated session names. Each session it saves on the DVD is named with the date and time it was created. How the Save script does that I have no idea. I just thought you might find it interesting to compare it to your way.
Thanks Flash, I'll check out /etc/rc.shutdown and see if I can figure out how Barry does it.

Post Reply