LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-07-2007, 05:09 AM   #1
Joejr4u
LQ Newbie
 
Registered: Nov 2006
Location: Dallas, TX
Distribution: SUSE 11, RHEL 6, Ubuntu
Posts: 9

Rep: Reputation: Disabled
Need tips on creating scripts for daily backup (tar) a directory to an external drive


Hi,

I need some tips on creating a script for daily backup of a large directory with tar to an external scsi drive.

The problem here is that, i need to have the script find the oldest tar archive and remove it so as to free space on the drive once its full (the size of the directory is between 80 and 100GB) and the size of the external drive is 500GB.

Also need to have a log file to keep track of the backup cuz i'm execute it as a cron job to run at night.

Would really appreciate ur kind suggestions? If possible an example script wuld help me speed things up. Its kinda urgent as i have to have it ready 2morow.

Thanks anyone.

Silverhawk.
 
Old 06-07-2007, 06:52 AM   #2
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Remove the oldest file
Code:
rm "$(ls -rt | head -1)"
Remove all files, except the three most recent ones
Code:
rm $(ls -t | sed -e '1,3d')
Note that for this last example, filenames cannot have spaces

Groetjes,

Kees-Jan
 
Old 06-07-2007, 07:46 AM   #3
fayez
Member
 
Registered: Aug 2004
Location: Amman
Distribution: Red Hat
Posts: 50

Rep: Reputation: 15
Or you can use the find command:

#find /bigdir -mtime +n -exec rm {}\;

where n is days, for example if you want to remove files created before 2 days replace n by 2. to be sure about the functionality of this command try it first with ls command:
#find /bigdir -mtime +n -exec ls -ltr {}\;
 
  


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
tar backup of an XP directory fof3 Linux - Newbie 2 03-31-2007 03:39 PM
tar: how to extract only one directory from a backup guarriman Linux - General 1 01-29-2007 10:35 AM
Doing backup of servers scripts using tar/gzip/scp/rm Swakoo Linux - General 4 12-05-2006 02:09 AM
tar backup & restore of current directory wishbone42 Linux - General 3 02-09-2004 02:30 AM
Using tar to backup a directory and subdirs n1wil Linux - General 1 08-07-2002 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:23 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
Open Source Consulting | Domain Registration