LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-16-2008, 04:03 AM   #1
fishy
LQ Newbie
 
Registered: Sep 2003
Posts: 15

Rep: Reputation: 0
tar backup scripts and file removal


Hi All

I have a little script that backs up to file and then copies to a USB key like so.....

# Remove old backup files to preserve space
rm -f /backup/Full*
# backup what I want and exclude some stuff
tar -zcvf /backup/"Full-Backup-$(date +"%d-%b-%y").tar.gz" --totals --exclude=*.mp3 /etc /home
# stop MySQL server to backup CRM
/etc/init.d/mysqld stop
# Backup CRM
tar -zcvf /backup/"Full-CRM-Backup-$(date +"%d-%b-%y").tar.gz" /var/lib/mysql/crmdb
# Restart MySQL
/etc/init.d/mysqld start
# Remove files from key, and copy new backups
rm -f /media/usbkey/Full*
cp /backup/Full* /media/usbkey

This works just fine, however I would like to keep two days worth of backups as opposed to one. Perhaps I need to use something with the date variable, along the lines of.... "if date of the file is todays date -2 then delete otherwise leave it"

Any help appreciated (note - I am not usually a scripting kinda guy!)
 
Old 02-16-2008, 04:35 AM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Here's what I use

find /storage/backups/ -name '*' -type f -mtime +30 -exec rm -f {} \;

Clearly this keeps up to 30 days (of weekly full backups)
 
Old 02-16-2008, 07:45 AM   #3
fishy
LQ Newbie
 
Registered: Sep 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by billymayday View Post
Here's what I use

find /storage/backups/ -name '*' -type f -mtime +30 -exec rm -f {} \;

Clearly this keeps up to 30 days (of weekly full backups)
Thanks - I can understand most of this too!
 
  


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
Need tips on creating scripts for daily backup (tar) a directory to an external drive Joejr4u Linux - Server 2 06-07-2007 07:46 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
Doing backup of servers scripts using tar/gzip/scp/rm Swakoo Linux - General 4 12-05-2006 02:09 AM
reading or deleting file from tar backup madhugp Linux - General 4 10-18-2006 02:30 AM
reading or deleting file from tar backup madhugp Linux - General 4 10-17-2006 08:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:36 AM.

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