Take advantage of Unix Environment Variables when performing backups or restore points Server backups or restore points require concludent file/folder names so you can recognize the date of this backup or restore point. What if there was an environment variable that would be exactly the date in d-m-y format ?
Server backups or restore points require concludent file/folder names so you can recognize the date of this backup or restore point. What if there was an environment variable that would be exactly the date in d-m-y format ?
An environment variable is a setting normally inherited or declared when a shell is started. You can use shells to set variables; the syntax varies but Bourne shells use:
$ VARNAME=new value $ export VARNAME or $ export VARNAME=new value
Usefull Variable in backups and restore points
Everytime I make a server backup or a restore point for some files or directories for my domain web server files, I use the command substitution $(date "+%d-%m-%Y") in order to have file names like: www.ivorde.ro.11-11-2007.tar.bz2 when I create tar or dump backups by command typing: tar jcpvf /the/backup/dir/www.ivorde.ro.$(date "+%d%m%Y").tar.bz2 /the/dir/of/my/domain/files.
After issuing this command and I use ls -lt to display files in my backup directory, ordered by modified date I have:
[root@server ~]# ls -lt /the/backup/dir/ total 252096 -rw-r--r-- 1 root wheel 31617360 Nov 14 16:29 www.ivorde.ro.14-11-2007.tar.bz2 -rw-r--r-- 1 root wheel 31621424 Nov 12 22:41 www.ivorde.ro.12-11-2007.tar.bz2 -rw-r--r-- 1 root wheel 31320820 Nov 8 11:15 www.ivorde.ro.08-11-2007.tar.bz2
Well, instead of typing each time $(date "+%d%m%Y") I will set a variable for my profile ($DATE or $WHATEVER) to be the exact output of the command date "+%d-%m-%Y"
Edit the /etc/profile or ~/.profile or .shrc or .bashprofile (whichever suits your needs) and add the following:
DATE=$(date "+%d-%m-%Y") export DATE
In my case I used /etc/profile file.
Now I reload it into the shell and echo the $DATE variable:
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.