Simple Backup Script

A simple unix-shell rotating backup script which only requires the ubiquitous date command.

As the days of the week change so do the files, last Monday's file gets replaced the following Monday. Last September's file gets replaced the following September.

Simple Instructions

Run a cronjob each day, e.g.

31 3 * * * /location/ > /location/logs/backup.log 2>&1

and in that file pass in a file with the same name, e.g. :


echo "My testfile" > ${DEST}/${FILENAME}

backup_rotate_store ${DEST} ${FILENAME}


The backup_rotate_store will make copies and replace when needed. After one year you'll have one one file for each of the 12 months, one for each of the last 4 weeks (plus one for the last days of the end of a month outside four weeks) and one for each of the last 7 days.


  • January.testfile.txt
  • February.testfile.txt
  • ...
  • December.testfile.txt


  • 1st.testfile.txt
  • 8th.testfile.txt
  • ...
  • 28th.testfile.txt


  • Sunday.testfile.txt
  • Monday.testfile.txt
  • ...
  • Saturday.testfile.txt

The maximum number of files stored is 12 + 5 + 7 = 24.

Suggested Use

  1. Clone this repo into a sub folder of your project.
  2. Copy the into your own project
    1. Edit the export part as needed (i.e. export the data you need into a file)
    2. Edit the include to point to the right directory.