LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2010, 07:10 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
file copy in script help needed


Hi guys ,

I m writing a script which will backup a perticular folder and its content to a different location.

this script needs to be run every weekend.

But my problem is how would i apply logic such that the previous backup folder is only deleted if and only if the current backup is successful.
 
Old 04-09-2010, 07:16 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Test the exit status at the end of your back up process and if successful remove the old backup
 
Old 04-09-2010, 07:29 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by grail View Post
Test the exit status at the end of your back up process and if successful remove the old backup
The location of file is same there fore it might overwrite existing files.
 
Old 04-09-2010, 08:06 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
You should copy the new backup to another directory and once you get a success remove the old directory and rename this fresh one to existing.
 
Old 04-09-2010, 07:22 PM   #5
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,031

Rep: Reputation: 63
Quote:
Originally Posted by pinga123 View Post
Hi guys ,

I m writing a script which will backup a perticular folder and its content to a different location.

this script needs to be run every weekend.

But my problem is how would i apply logic such that the previous backup folder is only deleted if and only if the current backup is successful.
Do google with bash and rsync.
 
Old 04-10-2010, 02:16 AM   #6
tommyttt
Member
 
Registered: Oct 2009
Location: Federal Way, WA
Distribution: openSUSE 11.4 x86_64, openSuSE 12.1, Fedora 15
Posts: 207

Rep: Reputation: 34
Since you're writing a script for this, why not give the backup a distinctive name, such as back.(date).type?

What I did in mine:
Code:
#  strip the "/" from directory name
Selection=${selection##/}     # trick from Josh Miller <joshua@itsecureadmin.com>

output="/BACKUP/$Selection-$(date +%d%b%Y).bz2"
echo "Doing full backup, from $selection,  saving output to $output"
Then it can't overwrite the previous backup. As Grail said, test the exit status and then delete the old backup.
I really prefer to have two or three levels backed up, never can tell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
write script to copy a file kavehiks Linux - General 5 10-21-2009 04:50 PM
can't find zm script file to copy. Buddhike G Linux - Software 1 10-08-2007 06:17 PM
Copy file between servers from script gr0undz3r0 Linux - Newbie 2 11-13-2006 12:48 PM
Copy file by script python ! BongHongXanh Programming 2 01-11-2006 09:26 PM
shell script to copy lines from a file Warmduvet Programming 2 09-14-2004 10:25 PM


All times are GMT -5. The time now is 12:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration