Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 30 Sep 2014, 10:39
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Backup savefile every "time interval" and Backup-on-Shutdown
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Author Message
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Mon 14 Feb 2011, 14:21    Post subject:  Backup savefile every "time interval" and Backup-on-Shutdown
Subject description: Fully automatic backup. Does not only backup savefile.
 

yes... so i made yet another backup thing.

I put this into /root/Startup, so i wont have to care about backing up again! Very Happy
I didnt use the backup-on-shutdown because i turn my computer on at 9am and shutdown at 7pm.
Don't want to potentially lose 8hours(assuming it fails at 6pm, and i took an hour's lunch break Wink ) of work.

You have to edit the script for it to work.
Code:

#!/bin/sh

#This is the time interval between 2 backups.
bacinterval="3h 12m 38s"

#Path to savefile
source=/mnt/home/lupusave-haha.3fs

#For the des, dont forget the "/" at the back!
des=/mnt/sda2/boot/Lupu51/Backup/

#This is the max number of backups. The oldest backup will get deleted.
maxbac=4

#If you are backing up to external hard drive. Uncomment the following 7 commented lines.
#externaldrive=/dev/sda2

for (( ; ; ))
do
##Put this at the buttom if you want to backup on boot. The double "#" is because i said "Uncomment the following 7 commented lines." lol.
   sleep ${bacinterval}

#   if mount|grep ${externaldrive};then
#   echo
#   else
#   mount /dev/sda2 /mnt/sda2
#   fi

   num=`find ${des} -maxdepth 1 -name *.bac | wc -l`
   if [ ${num} -ge ${maxbac} ];then
      rm -f ${des}"$(ls -t ${des} | tail -n 1)"
   fi

#I used "-close box" in case my mouse was on the splash as it appeared and i missed it. Go ahead and remove "-close box" if you want the splash to close when mouse-hover-over-splash. It wont be automatic with "-close box" btw. Add a timeout if your want it to backup while you are afk. I dont do this beause there will be nothing much to backup while i am afk.(ei. no data change)
   gtkdialog-splash -text "Backup is starting. Please do not shutdown till completed" -close box

#You might want to change this to something easier to view(eg. %a for abbreviated name(e.g. Sun)). Make sure you include the time or it will conflict when 2 backup in a day.
   date=`date +%T-%e-%m-%y`.bac

   cp -f "${source}" "${des}${date}"

#Same as above.
   gtkdialog-splash -text "Backup Completed" -close box
done


I added as many comments and spaces as i could to make the script look long Very Happy

Srsly, the spaces are to make the comments readable. If not it will be too messy.

Its only 23 lines... or 17 if you arnt backing up to external drive.

Feel free to remove my stupid comments. Wink
Edit4:Srsly... it looks very nice without the comments.

EDIT:Vladd44 suggested using tar.gz to save space.
This take a little longer than cp(possibily more cpu), but since its only once in a few hours... no harm done.
Since I have space to spare so i do not use this.

Just change
Code:
cp -f "${source}" "${des}${date}"
to
Code:
tar -czf "${des}${date}.tar.gz" "${source}"
And change
Code:
num=`find ${des} -maxdepth 1 -name *.bac | wc -l`
to
Code:
num=`find ${des} -maxdepth 1 -name *.bac.tar.gz | wc -l`


EDIT2: I put "sleep ${bacinterval}" at the top so it wont backup on boot.
Also, if you want your first backup to start at a different timing from the intervals, add "sleep 1h"(this is just an example) before "for (( ; ; ))". Then move "sleep ${bacinterval}" to the buttom(before "done")

EDIT3:
For people who leave thier computer on 24/7 and want to backup once per day at a specified time, you can use this
Code:
#!/bin/sh

#backup interval is 1day
bacinterval="1d"

source=/mnt/home/lupusave-ritchie.3fs
des=/mnt/sda2/boot/Lupu51/Backup/
maxbac=8
externaldrive=/dev/sda2

#Here you can specify what time you want the backup to be. Note that this is a 24h clock where 3pm = 15:00
dailybactime=03:15


currenttime=`date +%s`
sleeptime="$(($(date -d ${dailybactime} +%s) - ${currenttime}))"
if [ ${sleeptime} -le 0 ];then
targettmr="'$(date +%m/$((`date +%d` + 1))/%Y) ${dailybactime}'"
sleeptime="$(($(eval "date -d ${targettmr} +%s") - ${currenttime}))"
fi
sleep ${sleeptime}

for (( ; ; ))
do
   if mount|grep ${externaldrive};then
   echo
   else
   mount /dev/sda2 /mnt/sda2
   fi
   num=`find ${des} -maxdepth 1 -name *.bac.tar.gz | wc -l`
   if [ ${num} -ge ${maxbac} ];then
      rm -f ${des}"$(ls -t ${des} | tail -n 1)"
   fi
   gtkdialog-splash -text "Backup is starting. Please do not shutdown till completed" -close box
   date=`date +%T-%e-%m-%y`.bac
   tar -czf "${des}${date}.tar.gz" "${source}"
   gtkdialog-splash -text "Backup Completed" -close box
   sleep ${bacinterval}
done

Also, i just realize that "gtk-dialog splash" has an agruement, "-placement"
You could add "-placemement top" for example. Very Happy


IMPORTANT EDIT5: Im so sorry. I made a mistake for the compression thing. It should be "tar -czf" not "tar -cvf".
I changed the above one too.


EDIT6: added "Add a timeout if your want it to backup while you are afk." to comment on gtk-dialog splash.

Last edited by r1tz on Sun 20 Feb 2011, 11:20; edited 6 times in total
Back to top
View user's profile Send private message MSN Messenger 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Tue 15 Feb 2011, 09:32    Post subject: Backup on shutdown  

Making shutdown wait for tar/cp
Doing this will allow you to do without the splash(which tells you when the backup started and is done).
This way, auto backup will truely be "in the background".
At the start of the shutdown script, add
Code:

#change "tar" to "cp" if you are using cp to backup.
pid=$(pgrep '^tar$')
if [ "$pid" != "" ];then
ps -p$pid 2>&1 > /dev/null
status=$?
if [ "$status" == "0" ];then
while [ "$status" == "0" ]
do
sleep 2s
ps -p$pid 2>&1 > /dev/null
status=$?
done
fi
fi




To backup on shutdown

edit /etc/rc.d/rc.shutdown

Find
Code:
 fi
 busybox mount -t $SAVEFS -o remount,ro $SAVEDEV /initrd${SAVE_LAYER} 2>/dev/null
 umount-FULL -i -n -l /initrd${SAVE_LAYER} 2>/dev/null #-l is lazy unmount.
fi

Then put this underneth:
Code:

#Change this to something else if you want to change the default to "skip backup" instead.
doyouwanttobac=y

#You might also want to change this so it makes sense
echo "Backup?[input "y" to start or anything else to skip] Autobackup is 10seconds." >/dev/console

read -t 10 doyouwanttobac
if [ ${doyouwanttobac} = y ];then

#Note that the source is not "/mnt/home"
source=/initrd/mnt/dev_save/lupusave-ritchie.3fs
des=/mnt/sda2/boot/Lupu51/Backup/
maxbac=8

#drive to backup to(if applicable)
externaldrive=/dev/sda2

#drive that pupsave is in
externaldriv=/dev/sda4

   if mount|grep ${externaldriv};then
   echo
   else
   if [ -d /initrd/mnt/dev_save ];then
   mkdir /initrd/mnt/dev_save
   fi
   mount /dev/sda4 /initrd/mnt/dev_save
   fi
   
   if mount|grep ${externaldrive};then
   echo
   else
   if [ -d /dev/sda2 ];then
   mkdir /dev/sda2
   fi
   mount /dev/sda2 /mnt/sda2
   fi
   num=`find ${des} -maxdepth 1 -name *.bac.tar.gz | wc -l`
   if [ ${num} -ge ${maxbac} ];then
      rm -f ${des}"$(ls -t ${des} | tail -n 1)"
   fi
#i havnt test if the echo works... but even it doesnt, it will be obvious that it is doing the backup unless your pupsave is 1mb
   echo "Backup is starting." >/dev/console

   date=`date +%T-%e-%m-%y`.bac
   tar -czf "${des}${date}.tar.gz" "${source}"

#i dunno if this "wait" is needed. Please tell me if not needed.
   wait
fi



To have multiple source to backup from, you can do this
Code:

source=('/mnt/home/folder-to-backup-one' '/mnt/sda2/important-folder' '/mnt/sda3/veryimportant')
sourcenum=${#source[@]}

and add this into the bigger loop.
Code:

date=`date +%T-%e-%m-%y`.bac
for (( n=0;n<$sourcenum;n++)); do
    tar -czf "${des}${source[${n}]}${date}.tar.gz" "${source[${n}]}"
done

Last edited by r1tz on Sun 20 Feb 2011, 13:19; edited 5 times in total
Back to top
View user's profile Send private message MSN Messenger 
aarf

Joined: 30 Aug 2007
Posts: 3620
Location: around the bend

PostPosted: Tue 15 Feb 2011, 10:24    Post subject:  

It is a good idea
_________________

ASUS EeePC Flare series 1025C 4x Intel Atom N2800 @ 1.86GHz RAM 2063MB 800x600p ATA 320G
_-¤-_

<º))))><.¸¸.•´¯`•.#.•´¯`•.¸¸. ><((((º>
Back to top
View user's profile Send private message Visit poster's website 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Wed 16 Feb 2011, 05:16    Post subject:  

aarf, thanks
----

Can someone with skill i can only dream of make a GUI.
Something that allows the user to input all the values.
Then it will edit theshutdown script and make a script in /root/Startup accordingly?

Such a GUI will be a great addition to puppy. Very Happy
Back to top
View user's profile Send private message MSN Messenger 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Wed 16 Feb 2011, 07:26    Post subject:  

Hi r1tz,
for GUI there is Xdialog in puppy Lucid not sure about other puplets? or Zenity / Yad seems to be a bit easier to use here.
http://www.murga-linux.com/puppy/viewtopic.php?t=58306
Back to top
View user's profile Send private message 
aarf

Joined: 30 Aug 2007
Posts: 3620
Location: around the bend

PostPosted: Wed 16 Feb 2011, 08:56    Post subject:  

r1tz wrote:
aarf, thanks
----

Can someone with skill i can only dream of make a GUI.
Something that allows the user to input all the values.
Then it will edit theshutdown script and make a script in /root/Startup accordingly?

Such a GUI will be a great addition to puppy. Very Happy
perhaps you could interest zigbert in using/modifying the pschedule gui.
_________________

ASUS EeePC Flare series 1025C 4x Intel Atom N2800 @ 1.86GHz RAM 2063MB 800x600p ATA 320G
_-¤-_

<º))))><.¸¸.•´¯`•.#.•´¯`•.¸¸. ><((((º>
Back to top
View user's profile Send private message Visit poster's website 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Thu 17 Feb 2011, 01:28    Post subject:  

aarf wrote:
r1tz wrote:
aarf, thanks
----

Can someone with skill i can only dream of make a GUI.
Something that allows the user to input all the values.
Then it will edit theshutdown script and make a script in /root/Startup accordingly?

Such a GUI will be a great addition to puppy. Very Happy
perhaps you could interest zigbert in using/modifying the pschedule gui.


Im not too sure about that. The pschedule looks alot more like a gui for cron and i dont think it really is suited for this purpose.

stu90 wrote:
Hi r1tz,
for GUI there is Xdialog in puppy Lucid not sure about other puplets? or Zenity / Yad seems to be a bit easier to use here.
http://www.murga-linux.com/puppy/viewtopic.php?t=58306

yad looks nice. I think i might try it.

However i have not made any gui expect for my crappy opera profile changer http://www.murga-linux.com/puppy/viewtopic.php?p=494789 which has a lot of bugs(becuase i try to do it as a gui).
In other words i have about 0 experence in making gui.

I will need to learn how to use yad.... and hopefully be able to make a decent gui.

Im quite busy atm so it will be sometime before i actually make something useful.

I want to make a gui with as many options as possible.
Back to top
View user's profile Send private message MSN Messenger 
don570


Joined: 10 Mar 2010
Posts: 3307
Location: Ontario

PostPosted: Thu 17 Feb 2011, 20:23    Post subject: learn how to make GUI  

The method I used to learn to make a GUI was to study the
program mtpaintsnapshot.sh which is installed in most Puppies.

I rewrote the program to localize it
http://www.murga-linux.com/puppy/viewtopic.php?p=496476#496476

You should take a look at my timer program
http://www.murga-linux.com/puppy/viewtopic.php?p=496479#496479




___________________________________________________________
Back to top
View user's profile Send private message 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Fri 18 Feb 2011, 00:06    Post subject: Re: learn how to make GUI  

double post. sorry
Last edited by r1tz on Sun 20 Feb 2011, 08:40; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Fri 18 Feb 2011, 00:08    Post subject: Re: learn how to make GUI  

don570 wrote:
The method I used to learn to make a GUI was to study the
program mtpaintsnapshot.sh which is installed in most Puppies.

I rewrote the program to localize it
http://www.murga-linux.com/puppy/viewtopic.php?p=496476#496476

You should take a look at my timer program
http://www.murga-linux.com/puppy/viewtopic.php?p=496479#496479


Thanks, i thing that will aid me in learning how to make a gui.
Documentation on zenity and yad seems abit hard to find...

btw, I tried yad for the first time yesterday, made a theme changer for geany http://murga-linux.com/puppy/viewtopic.php?t=64946.
Back to top
View user's profile Send private message MSN Messenger 
PaulBx1

Joined: 16 Jun 2006
Posts: 2308
Location: Wyoming, USA

PostPosted: Sun 20 Feb 2011, 00:44    Post subject:  

I did something like this a while back. The howto is floating around here somewhere. That was when I had a big, valuable pupsave (full of emails and so forth).

Now I have a small pupsave and all personal stuff is saved outside of it. I back up the pupsave once and then forget it. Easy to recover.

Does my off-pupsave stuff now get backed up regularly? Er, no. Embarassed
Back to top
View user's profile Send private message 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Sun 20 Feb 2011, 08:37    Post subject:  

PaulBx1 wrote:
I did something like this a while back. The howto is floating around here somewhere. That was when I had a big, valuable pupsave (full of emails and so forth).

Now I have a small pupsave and all personal stuff is saved outside of it. I back up the pupsave once and then forget it. Easy to recover.

Does my off-pupsave stuff now get backed up regularly? Er, no. Embarassed

You can always use tar to backup normal folders.(see first post)

Refer at post2 for having more than one source to backup from, i edited it.

This way you can backup multiple normal folders. Very Happy
Back to top
View user's profile Send private message MSN Messenger 
nooby

Joined: 29 Jun 2008
Posts: 10557
Location: SwedenEurope

PostPosted: Sun 20 Feb 2011, 10:49    Post subject:  

I love this thread. Would be cool to have as small save file as possible and to ahve it backed up regulary and safely without too much delay.

I often screw up the save file with programs that get messed up.

So looking forward to what you try to achieve there.

_________________
I use Google Search on Puppy Forum
not an ideal solution though
Back to top
View user's profile Send private message 
r1tz


Joined: 09 Sep 2010
Posts: 165
Location: In #puppylinux (IRC)

PostPosted: Sun 20 Feb 2011, 11:01    Post subject:  

Added "how to make shutdown wait for tar/cp" in the second post.
This way, we can do without gtk-dialog splash.

Then it will be really automatic and in the background!


EDIT: 14/4/2011
Blah, i still cant make a good GUI.

Anyone else want to do it? Very Happy
Back to top
View user's profile Send private message MSN Messenger 
Luluc


Joined: 16 Mar 2011
Posts: 200

PostPosted: Tue 19 Apr 2011, 05:37    Post subject:  

This is very useful, thanks. I just implemented this for myself.

However, instead of the 'cp' or the 'tar' command, I'm using 'rsync -aHxzv --no-whole-file'. That command will use rsync to make an incremental backup. No matter what your file is, rsync will compare individual raw blocks and update only those that have been changed in comparison with an existing target file. So instead of copying the entire file over again, it will likely copy just 10% or 20% of it, just the parts that changed. The rest is not necessary. It is a much faster procedure.

Best regards.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [16 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1221s ][ Queries: 12 (0.0064s) ][ GZIP on ]