Preliminary Info: Starting with names like Tech_backup1.tar.gz tech_backup11.tar.gz tech_backup41.tar.gz under the / home / backup folder. The Tech_backup part is fixed, followed by a random number of GZ compressed files. All of them have a different creation date.
The bash / shell script you will write should include the following steps.
1. Find the last file created from these files.
2. Extract this file from the GZ. (The name of the file inside is the same as the compressed file, instead of just the tar.gz part, the extension of the file is bck. Ex: Extracted version of the tech_backup11.tar.gz file is named tech_backup11.bck)
3. Create a folder under / var / Tech / backups / if there is no folder with today's date (Format YYYY-MM-DD). (Ex: Folder layout: / var / Tech / backups / 2020/12/28)
4. Transfer the parsed file from step 2 to the folder in step 3.
5. Make sure that under the / var / Tech / backups / folder, there are only files and folders for the last 30 days. (delete old ones)
6. Compress the file under the / home / backup folder with the same name and add the date format information specified in item 3 to the end with tar.gz. (For example: Tech_backup11.bck file Tech_backup11-2020-12-28.tar.gz)
We can use below sample script for taking the backup,