Linux Tips 8: Time stamp file names for backups or archives

|
When doing simply backups (non-incremental) it is useful to be able to automatically time stamp or date stamp file names. This makes archives much easier to navigate when it comes time to retrieve a backup.

The command for doing this is quite simple. To just create a file with a time stamped file name, use the following command:

touch myfile-$(date '+%Y-%m-%d-%T')
The command will produce a file called myfile-2009-02-25-17:32:01 You can also use it to make backups when combined with tar. The following code will create a date stamped gzipped tar file of a directory called test.

tar czvf test_backup_$(date '+%Y%m%d').tgz test/
Using the above commands with cron can allow you to quickly create a very simple, yet effective, backup system for any important folders that you need to archive.

0 comments:

Post a Comment