UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 30th, 2005, 03:56 AM
Veus Veus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 11 Veus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 48 sec
Reputation Power: 0
Problem with backup script

Hi,

I have a backup script which runs every 6 hours and backs up everything to a new directory.

My problem is that the script is meant to delete directories which have been created more than a day ago.

I have other scripts like that and they work perfectly its just this one.

Code:
#!/bin/sh
#Setup directory
BACKUPDIR=`date +%d`'-'`date +%m`'-'`date +%y`'--'`date +%T`

#Create directory
mkdir /backup/acornbackup/html/$BACKUPDIR/
chown acorn:acorn /backup/acornbackup/html/$BACKUPDIR
chmod 655 /backup/acornbackup/html/$BACKUPDIR

#Rsync data to new directory
rsync -a /home/acorn/public_html /backup/acornbackup/html/$BACKUPDIR/

OLD=`date +%d --date='1 day ago'`'-'`date +%m --date='1 day ago'`'-'`date +%y --date='1 day ago'`'--'`date +%T --date='1 day ago'`
cd /backup/acornbackup/html
for file in $OLD
do
        if [ ! -e "$file" ]
        then
                continue
        else
                rm -Rf $file
        fi
done

Reply With Quote
  #2  
Old August 30th, 2005, 06:01 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
Code:
find /folder/ -type d -ctime 24 -exec rm -rf {} \;

Read: Find all entries below "/folder/" of type "directory" created at least 24hrs ago and pass the file names to "rm -rf".

Test thoroughly before using in a production environment! You may end up deleting your whole filesystem if something goes wrong, eg. if the top folder is aging...

hth,
M.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old August 30th, 2005, 06:19 AM
Veus Veus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 11 Veus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 46 m 48 sec
Reputation Power: 0
Thanks for the reply.

The thing is that each folder is timestamped so i can just look at that instead of looking at the folder as it will be a bit safer

Thats what I used for the other scripts anyway

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Problem with backup script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway