I have a shell script that runs every night to back up my database of EC2 and html sites to S3, and when it supports folders up, it adds a date to it to make browsing easier. But I want him to also be able to delete the corresponding folders for backup 3 days before. How can I do the calculations to get the date 3 days ago?
#!/bin/bash DATE=`date +%m%d%Y` s3cmd put -r /var/lib/mysql/mydb/ s3://mybucket/mydb-$DATE/ s3cmd put -r /home/ec2-user/public_html/ s3://mybucket/public_html-$DATE/ s3cmd del -r s3://mybucket/mydb-(date 3 days ago)
You can use the -d flag for the date command:
-d, --date=STRING display time described by STRING, not 'now'
So, just change your date variable to:
DATE=`date +%m%d%Y -d "3 days ago"`
Why don't you use directory modification time? Then you can just find them with find. For exmaple:
find backups -maxdepth 1 -mtime 3
Source: https://habr.com/ru/post/890957/More articles:Test for Google Closure Library - performanceDjango server slower with chrome + another instance / browser - google-chromeQuestion about setting autopilot in C # - c #MS Excel for HTML-grid is missing in Google Chrome - htmlForce Safari include Origin header in jQuery GET request - javascriptShould a UIView reference a UIViewController? - uikitWhy is the subsequent direct method call much faster than the first call? - performanceWhy is the second cycle of the cycle always faster than the first? - performanceCreating / displaying an image from dataURL - php(still) cannot install lxml 2.3 for python correctly, but at least 2.2.8 works - pythonAll Articles