CLI Remove old backup file max 5 older
We have provided a set of command-line instructions for managing backup files. These commands are designed to remove older backup files based on certain criteria. Let me break down each of the commands for you:
-
Removing Old Backup Files Using
ls,tail, andxargs:1ls -t1 | tail -n +11 | xargs -d '\n' rmThis command is used to list files in a directory by their modification time in descending order (
-t1). Then, it usestailto exclude the top 10 files (keeping the 11th and onwards), and finally, it usesxargsto remove these older files. -
Removing Old Backup Files Using
rmandls:1 2 3cd /DataVolume/shares/john/Backups/DockerBackup/example-server rm -f `ls -t ??-??-??.tgz.gpg | sed 1,5d` cd ~This set of commands does the following:
- It navigates to the specified directory.
- It lists files matching the pattern
??-??-??.tgz.gpgin descending order of modification time usingls -t. - It uses
sed 1,5dto remove the first 5 lines (files) from the list. - Finally, it removes the remaining files using
rm.
-
Using the ‘drive’ CLI to Push and Delete Backup Files:
1 2drive push --no-prompt -destination backups/example-server/Dockers/ *.gpg drive delete --quiet `drive list --files backups/example-server/Dockers/ | grep gpg | cut -c 2- | sed 1,5d`These commands involve the “drive” CLI for interacting with Google Drive. Here’s what they do:
- The first command pushes all
*.gpgfiles from the current directory to the specified destination in Google Drive, without prompting for confirmation. - The second command deletes the oldest 5
*.gpgfiles in the “backups/example-server/Dockers/” directory on Google Drive. It lists the files, filters for those with “gpg” in their names, removes the first 5 files usingsed, and then deletes them usingdrive delete.
- The first command pushes all