ant2009
ant2009

Reputation: 22526

Writing a script file to create a new folder based on the current date

CentOS 5.3

I have a script file that works for backing up a repository and I am using rsync to copy the contents to the source directory.

I have a crontab job that runs every night at 12am that calls my script file. repos_backup.sh

rsync -razv [email protected]:repos /home/backup_sys_user/repos_backup

However, this puts all the repositories in repos_backup directory. However, I am looking for a way to create a new directory based on the date the backup was done. So I should have a directory structure like this:

/repos_backup/10.10.2010
             /11.10.2010
             /12.10.2010

I haven't done much scripting before, is there anyway to do this.

Many thanks for any advice,

Steve

Upvotes: 0

Views: 294

Answers (1)

Eric Wendelin
Eric Wendelin

Reputation: 44349

You can use:

date +%m.%d.%Y

To get the current date (e.g. 10.10.2010)

To include it within a command, you can do:

mkdir ~/myuser/`date +%m.%d.%Y`/backup

Note that the those are tick marks.

Upvotes: 1

Related Questions