Shell Script Create List of Deleted Files

Hi,

I want to put all the deleted files in a txt file. Because i want to backup my image server which has thousands of jpg images. I wrote a shell script which will copies images from image server to backup image server. I setup a cronjob which runs on every five minutes. & through timestamp it tooks last five minutes jpg images and copies to Backup Image Server.

Now the problem is that when any image (jpg) deleted from Original Image Server how can i took this to also delete that image from Backup Image Server.

So, in order to meet that i believe i will put all the deleted jpg names (file names) into a text file and use that file to delete images from Backup image server.

So, can any one please let me know the commands how can i put deleted *.jpg files into text file so i can this on Backup image server to delete images.

Or let me know any other solution ?

Regards,
Muhammad Irfan

as an alternative, why don't you check if you can use rsync? to know more about rsync, check here

Yogesh,

Thanks for your reply. we don't want to use rsync. It is much havier. Can u please let me know how to record names of deleted files in a text file ?

Regards,
Muhammad Irfan

who deletes the files? and how?

if files are being deleted from an application / script, then before deleting them, you can add an entry in a file.

Yogesh,

On image server files are stored in random order. These are user images which are saved by our paid clients through website. For example

root@linux/root/images} ls -la
root@linux/root/images} 12345.jpg
root@linux/root/images} 12346.jpg

If any user delete image from the application. The image also deleted from the image server (off course). Let suppose 12345.jpg & 12346.jpg was deleted. I want when those images deleted the name of those images (12345.jpg & 12346.jpg) shall stored in a file.txt.

So i can use that file.txt to delete those images from Backup Image Sever which are copied through Shell Script. When those images are deleted from Backup Image Server. Both Servers are Synchronized.

Which is the AIM of doing that. Looking forward to hear from you.

Regards,
Muhammad Irfan

Hi! prior to any deletion, you can try getting all the list of files and redirect it to a text file, then after the deletion or at any given time you might want to get all the list of files again and pipe it to another text file and compare that with the older file using maybe diff.

To check for the files which are in jpg format you can use the find command.

Also, why don't you try d above suggestion of using rsync. Rsync would be the best thing for this situation.

Thanks for your reply you.

Well this solution comes to my mind but again the problem i have around 10 subdirectories beneath in images directory. So this is little bit difficult to manage this. Still i think the best option is define user define function in shell script whenever any jpg file deletes it record the name of that jpg file in a txt file & then simple delete file from another server by using that file.

I done this in past through shell script but i forgot what commands i used. Can u let me know about my scenario how is that ?

Regards,
Muhammad Irfan

What backup scheme are you using? Is it within the LAN or an offsite backup? If I were you, I would discard my current backup process and go with rysnc. It will automate the process of deleting files deleted from the source machine.

Thanks for suggestion yongitz.

I also first decided to go with rsync. But one of senior collegue having trouble with that in past. Because our image server has thousands of listing in image directory and beneath.

So he is saying rsync will first do ls -la in directory and then compare with backup image server in the same directory. So doing this comparison it eats lots of I/O & increases server load rapidly as result of ls -la yields thousands of listings. By the way i didn't try rsync anyhow.

So that is one of the problem i didn't go with rsync.

Are you agree that rysnc creates prolbems in our scenario ?

Is their any other way ?

Or can you let me know the advantages & Disadvantages of rsync ?

Our structure is

root@linux/images } ls -la
root@linux/images } 1/ --> 12/ --> 123 --> having 20,000 listing jpg's
root@linux/images } 2/ --> 21/ --> 211 --> having 25,000 listing jpg's
root@linux/images } 3/ --> 31/ ---> 311 --> having 30,000 listing jpg's
root@linux/images } continue ...
root@linux/images } continue ...