>_ IzzyLab

Hands-on task

This task is step 11 of the course “Archives and backups”

Pack up outdated exports

medium~7 min

The /srv/exports directory keeps swelling with daily CSV exports. Pack all .csv files older than 30 days into the archive /root/exports-old.tar.gz and delete the originals. Leave newer exports and files of other types where they are.

What you'll practise:
  • find
  • -mtime
  • tar
  • gzip
  • archiving by age

Topic breakdown

Archiving "everything older than N days" is two steps with the same selection. First find locates files by name mask and age: the predicate -mtime +30 means "modified strictly more than 30 days ago", and a file exactly on the boundary won't be selected. The list of matches is handed to tar (it reads names from a file or from stdin), which compresses the archive with gzip right away. Only once you're sure the archive exists are the originals deleted with the same find plus the -delete action — the identical filter guarantees that exactly what was packed disappears, while fresh files and files of other types stay.

What's checked

  1. old exports packed into exports-old.tar.gz
  2. originals of old exports deleted
  3. fresh exports and README stayed and didn't go into the archive

What it looks like