Backup date

Backing up is very important and keeping the backups organised is vital as you need to be able to locate the exact backup you need easily at any given time.

There are many backup programs which will manage the backup for you and it will do a very good job as well, the problem is cost. These programs cost a lot of money in terms of licensing and storage. Whilst it will work for large corporations, smaller websites such as blogs and small medium enterprises may struggle with the upfront cost.

By creating your own backup system, you can maintain your own storage system which is configurable based your requirements, that way you don’t need to use the tools which they provide as your creating your own tool.

The first step is to create a folder for each backup which will contain the backup itself. The folder needs to be unique and it shouldn’t get replaced. The most accurate time would be the server time, we can make use of the “date” command is it will list all the information we need.

Sat May  2 13:13:56 BST 2015

The information listed starts with “Sat” there are 52 weeks in the year and we will have 52 “Sat” to search through if we is looking for a backup which was on Saturday. Whilst we can filter the results via searching, the information wouldn’t be easily readable by a human. We can look to modify the date accordingly through the use of regular expression and data filtering.

mkdir "`date +20%y-%m-%d`"

This will create a directory folder in the current path with the name of “YYYY-MM-DD”. The source of the date is from the server itself. When we list the folders, we will have multiple folders of backups in a human readable format.

mkdir "`date +%F`"

The above method is a cleaner way to do it rather than making use of multiple arguments.