[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Handy backup rotation bash script

Posted on 2012-08-29
12
Medium Priority
?
404 Views
Last Modified: 2013-01-24
I have bunch of files named xxx-20111201.gz, xxx-20111202.gz, ..., xxx-20111231.gz, ...., xxx-20120830.gz.

I need to rotate this files leaving only two last backups in each month.
The problem is that I do not always know if there will be backups for 30, 31st of each month. There is a possibility that all of them will be missing except for example couple for the first and second day of the month than I need to keep this two avalable  backups for this month.

Is there any handy way to do this rotation in a bash script?
0
Comment
Question by:twolines
10 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 38348627
Do you want to delete all but the last two files in each month?
0
 

Author Comment

by:twolines
ID: 38348909
yep
0
 
LVL 85

Expert Comment

by:ozo
ID: 38348937
perl -e ' /(.*)\d\d\.gz/ and ++$n{$1}>2 and unlink for reverse <*.gz>'
0
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
LVL 81

Expert Comment

by:arnold
ID: 38348953
find /path/to/the/backups -name "xxx*.gz" -mtime +3
The above should return all backups that are older than three days.
Adding -exec rm {}\; to the above find line

How often are you considering running this cleanup script?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 38792432
I've requested that this question be closed as follows:

Accepted answer: 500 points for arnold's comment #a38348953

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
LVL 85

Expert Comment

by:ozo
ID: 38790253
Was there any problem with the answer in http:#a38348937 ?
0
 
LVL 85

Expert Comment

by:ozo
ID: 38792425
As I understand the question, http:#38348953 does not seem to satisfy its requirements, while http:#a38348937 does.
0
 
LVL 85

Expert Comment

by:ozo
ID: 38792433
As I understand the question, http:#38348953 does not seem to satisfy its requirements, while http:#a38348937 does.
0
 
LVL 85

Accepted Solution

by:
ozo earned 1500 total points
ID: 38795450
Did I misunderstand the question?  How how does  http:#38348953 answer the question and how does http:#a38348937 not answer the question?
It appears that http:#38348953 would delete all backups for prior months, and only keep the last 3 days, whereas http:#a38348937 keeps the last two in each month as per request.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 38813587
I've requested that this question be closed as follows:

Accepted answer: 250 points for arnold's comment #a38348953
Assisted answer: 250 points for ozo's comment #a38348937

for the following reason:

Starting auto-close process to implement the recommendations of the participating Expert(s).<br />&nbsp;<br />modus_operandi<br />EE Admin
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
The Internet has made sending and receiving information online a breeze. But there is also the threat of unauthorized viewing, data tampering, and phoney messages. Surprisingly, a lot of business owners do not fully understand how to use security t…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question