[NTLUG:Discuss] cop files with dynamic prefix

Stuart Johnston saj at thecommune.net
Thu Dec 14 13:43:54 CST 2006


The shell script would be pretty simple.  Something like:

DATE=`date +%Y%m%d`
cp -a somepath/myfolder/ backup/myfolder$DATE/

However, you might want to consider using something like rdiff-backup, Dirvish or one of the many 
rsync-based backup scripts.


m m wrote:
> All:
> 
> Can anyone help me with a script?
> 
> 1. copy all files and sub directories in myfolder to backup directory
> 2. create a directory under backup and automatically add date as prefix
> 3.  copy all files and sub directories in myfolder to newcreated directory
> 
> for example
> 
> the original folder/files
> somepath/myfolder/*
> 
> after copy on the day of 12/14
> the folder  will have
> backup/myfolder12142006/*
> 
> and
> 
> after copy on the day of 12/14
> the folder  will have
> backup/myfolder12142006/*
> backup/myfolder12152006/*
> ...
> 
> Does the shell can do it or need other 'language' tool (such as perl...) to 
> achieve this task?
> Any code example would be appreciated!
> 
> thanks.
> 
> _________________________________________________________________
> MSN Shopping has everything on your holiday list. Get expert picks by style, 
> age, and price. Try it! 
> http://shopping.msn.com/content/shp/?ctId=8000,ptnrid=176,ptnrdata=200601&tcode=wlmtagline
> 
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss




More information about the Discuss mailing list