|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Problem with backup script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|