Quote:
Originally Posted by eklavya
We need to see your efforts first. What have you written so far? Paste your code here and we will definitely help you to solve your problem.
If new back-up file is always going to be saved as backup-.*-3.tar.gz, you need to remove first backup-.*-1.tar.gz, then rename backup-.*-2.tar.gz into backup-.*-1.tar.gz and backup-.*-3.tar.gz into backup-.*-2.tar.gz, so your backup directory will have only three files always. First try on test directories and test files.
It is just bunch of step by step commands, there is no rocket science.
|
I have written the code can you help me to modify it
k=$(ls /syslink/.sram_copy/backup*.tar.gz 2> /dev/null | wc -l)
l=`expr $k + 1`
myfile=/syslink/.sram_copy/backup-$(date +%Y%m%d-%H%M%S)-$l.tar.gz
if [ $k -eq 3 ]
then
i=1
rm /syslink/.sram_copy/backup*$i.tar.gz
rm /syslink/.sram_copy/backup*$i.tar.gz.md5
i=`expr $i + 1`
while [ $i -le 3 ]
do
filename=$(ls /syslink/.sram_copy/backup*$i.tar.gz)
filename=${filename##*/}
j=`expr $i - 1`
filename1=/syslink/.sram_copy/${filename%-*.*}-${j}.tar.gz
mv /syslink/.sram_copy/$filename $filename1
md5sum $filename1 > $filename1.md5
rm /syslink/.sram_copy/$filename.md5
i=`expr $i + 1`
done
tar zcf /syslink/.sram_copy/backup-$(date +%Y%m%d-%H%M%S)-3.tar.gz /sramdisk/ > /dev/null 2>&1
myfile=$(ls /syslink/.sram_copy/*3.tar.gz)
md5sum $myfile > $myfile.md5
elif [ $k -eq 2 ]
then
tar zcf $myfile /sramdisk/ > /dev/null 2>&1
md5sum $myfile > $myfile.md5
elif [ $k -eq 1 ]
then
tar zcf $myfile /sramdisk/ > /dev/null 2>&1
md5sum $myfile > $myfile.md5
elif [ $k -eq 0 ]
then
tar zcf $myfile /sramdisk/ > /dev/null 2>&1
md5sum $myfile > $myfile.md5
fi