
September 8th, 2011, 02:04 PM
|
|
|
First things first, you may have got the order in which you wish to do that wrong ...!
Zip up oldest archive and remove those files
Move day 1 stuff to day 2
Move current to day 1
Having spaces in the directory names may be an issue, so take care with those.
At the relevent time (maybe via cron?) have the 'archive process' fire off:
Code:
arch_date=$(date "+%F")
zip -q /archive/${arch_date} "/archive/2 days ago"
zip_cc=$?
if [ $zip_cc -ne 0 ]
then
echo "Zip error (code $zip_cc)"
exit 1
fi
rm "/archive/2 days/ago/*"
rm_cc=$?
if [ $zip_cc -ne 0 ]
then
echo "rm error (code $rm_cc)"
exit 1
fi
mv "/archive/1 day ago/*" "/archive/2 days/ago/"
mv_cc=$?
if [ $mv_cc -ne 0 ]
then
echo "mv error from 1 day ago (code $mv_cc)"
exit 1
fi
mv "/fred/*" "/archive/1 day ago/"
mv_cc=$?
if [ $mv_cc -ne 0 ]
then
echo "mv error from fred (code $mv_cc)"
exit 1
fi
Not tested and, as always, before implementing anything that deletes/moves stuff about be very sure you have a working backup and that the things being deleted and moved have been identified correctly!
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|