LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-22-2017, 03:38 AM   #1
vijaymaurya
LQ Newbie
 
Registered: Jan 2017
Posts: 23

Rep: Reputation: Disabled
Find file in folder and compare with younger one and then delete


Hi,

We have scheduled backup to our FTP server and backup run everyday and created tar file for every day.

The file size for each day backup is 6.5GB, we want to keep backup of 7 days backup and delete all.

Right Now we are doing it manually every day, i have find the script by which i can view the file which is older than 7 days.

find /var/dtpdev/tmp/ -type f -mtime +17 but i need script which should first check the the file is available for recent days and delete
file which is older than 7 days.

Kindly help.

Thanks to all of you.
 
Old 05-22-2017, 03:50 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 3,521
Blog Entries: 3

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
Quote:
Originally Posted by vijaymaurya View Post
find /var/dtpdev/tmp/ -type f -mtime +17 but i need script which should first check the the file is available for recent days and delete
file which is older than 7 days.
Ok. What kind of naming or directory scheme do you have to be able to tell the old file from the new file?

Have you looked at logrotate to see if that does anything useful for you?

Also, by "FTP" I hope you really mean SFTP and that "FTP" was just a typo.
 
Old 05-22-2017, 09:40 AM   #3
vijaymaurya
LQ Newbie
 
Registered: Jan 2017
Posts: 23

Original Poster
Rep: Reputation: Disabled
Find file in folder and compare with younger one and then delete

Quote:
Originally Posted by Turbocapitalist View Post
Ok. What kind of naming or directory scheme do you have to be able to tell the old file from the new file?

Have you looked at logrotate to see if that does anything useful for you?

Also, by "FTP" I hope you really mean SFTP and that "FTP" was just a typo.
Thanks for your reply.

We have configured some of our crucial server config backup on our VSFTP server, the path is below where the daily backup file get stored.

/home/nableftp/NableBackup

-rw-r--r-- 1 nableftp nableftp 41 May 11 23:55 20120611HHMM.tar201705120003-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6795980800 May 11 23:55 20120611HHMM.tar201705120003-daily.tar
-rw-r--r-- 1 nableftp nableftp 41 May 12 23:23 20120611HHMM.tar201705122333-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6468096000 May 12 23:23 20120611HHMM.tar201705122333-daily.tar
-rw-r--r-- 1 nableftp nableftp 41 May 13 23:23 20120611HHMM.tar201705132333-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6258421760 May 13 23:23 20120611HHMM.tar201705132333-daily.tar
-rw-r--r-- 1 nableftp nableftp 41 May 14 23:23 20120611HHMM.tar201705142333-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6290544640 May 14 23:23 20120611HHMM.tar201705142333-daily.tar
-rw-r--r-- 1 nableftp nableftp 41 May 15 23:28 20120611HHMM.tar201705152338-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6331627520 May 15 23:28 20120611HHMM.tar201705152338-daily.tar
-rw-r--r-- 1 nableftp nableftp 41 May 16 23:23 20120611HHMM.tar201705162333-daily.sha1
-rw-r--r-- 1 nableftp nableftp 6373580800 May 16 23:23 20120611HHMM.tar201705162333-daily.tar

So every day backup run and create 6.5 GB file which is in tar , i need to createdelete script in such a way that it should delete file which folder than 7 days.

But before deleting it should make sure that the file newer than 7 days available.

Thanks to all of you.
 
Old 05-22-2017, 10:03 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro / Parrot
Posts: 7,176

Rep: Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437Reputation: 1437
you got dates attached to your files why not just look for the oldest date then delete it. they all have the same date pattern.

I do not know what the 41 is but may 11th (month-day [no year])
Code:
May 10 <--- this one gets deleted
May 11 <- 
..through ...
May 17 < -- current file minus 7 days = 10 delete that one so remaining are only up to seven days of back ups.
get the current file date month day then minus 7 getting you the oldest one there then delete it.

whatever commands you are using to created that back up . just put that into the script. then next, using that current date added to that file reverse back looking for that one file that is now number 8 then delete it using the date pattern. bringing it back to 7 files total.

forethought:

Mounts will need a define to them for when you are in between months.
ie.

May 31
June 1
using
May=5
June=6

because being in between months using the month numbers now to be sure that i am getting the right file as well.

because
Code:
 (june) 1 - 7 = -6
Then their is the 28 day months and 30 day months you are to calculate for.

But I am sure (I just have not looked into it) that someone has already thought that out and added it to a find -argument perhaps. or some such utility that already does the math for such same situations.

so this script you need should do what?

Code:
1. create back up
2. use that date applied to back up to calculate back 7 or 8?
3. delete that 8th file
4. done

Last edited by BW-userx; 05-22-2017 at 10:46 AM.
 
Old 05-22-2017, 10:03 AM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 3,521
Blog Entries: 3

Rep: Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567Reputation: 1567
You have find which can tell you the names of the old files. Next write a script that will take that file name and take its stem and look for fresher files with that same stem. Then combine that with the first find

How far can you get with that?

http://tldp.org/LDP/abs/html/paramet...ml#PARAMSUBREF


(VSFTP uses TLS only if you have gone out of your way to set it up. If you have gone out of your way to set up TLS you will have FTPS not SFTP. If you haven't either FTPS or, better, SFTP then you have a problem on your hands.)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect one file in a folder and delete everything i that folder. Entropy1024 Linux - Newbie 6 12-18-2016 01:30 PM
find folders in a folder and delete ibbofez Linux - Newbie 3 10-26-2011 05:20 PM
Find folders with ONLY one specific file in and delete file and folder - How ? gedi1 Linux - Newbie 5 10-21-2009 09:09 PM
How to compare two lines and delete the duplicate line from a file? Shobhna Linux - Newbie 10 12-05-2008 02:08 PM
Script to Compare Folder Structures and File Contents rajaniyer123 Solaris / OpenSolaris 2 11-11-2008 02:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration