hello mark, On 08/19/2013 01:56 PM, Mark Haney wrote:
I've hit a problem I can't quite figure out which a bash script I'm writing. I'm trying to copy backup files in the format 2013-August-18--1123.zip to an NFS share. I want to have the script copy the file with just the date. In bash I've setup vars that get the current date: # Date variables log_year=`date "+%Y"` log_month=`date "+%B"` log_day=`date "+%d"`
>
# Filename format YYYY_MM_DD--HHMM.zip filename=$log_year"-"$log_month"-"$log_day"--"/*".zip"
why are you showing "/*" in your "filename=" statement? such would indicate date as a directory and _all_ files in a directory that ends with "zip". if you meant to _delimit_ the "*", then "\" is used to delimit. i believe actual 'filename' should be; $log_year"-"$log_month"-"$log_day"*.zip"
The problem is I don't really care about the stuff after the '--'.
you better care about it as it is written, as, for what you want, 'filename' would be as i present.
I.e. from the CLI I'd just 'ls 2013-August-18--*.zip' to get all the
> files with that date in the file name. How can I do that in a bash script? not if you use the "/*". problem just might be that you have worked with it too long and not really seeing what you are doing. ;=) ls 2013-August-18--*.zip should show _all_ files for 18 august, 2013, regardless of time, in 'current' directory. if not, something is bad wrong. when i time stamp a backup file, i use; yyyy-mmdd-hhmm-filename or filename-yyyy-mmdd-hhmm then, when i collect them for transfer to backup tape media, i use; find . yyyy-mmdd-* | sort | cpio -o -[arguments] /dev/tape or find . *-yyyy-mmdd | sort | cpio -o -[arguments] /dev/tape which finds _all_ files of *-yyyymmdd or yyyymmdd-* and they are backed up. [and yes, i use *yyyymmdd* for various reasons] not that much difference if you are using multi "-". from 1 of my script files; find $1 -depth | sort | cpio -o -Bcmv > [path to backup file]$2.cpio and then backup the *.cpio file. "$1" and "$2" are passed to script from command line. i have a rather extensive collection of script files that i use for tape backup that i have used for years for both argument passing and no argument passing for regularly preformed backups with out problems. i can not access the extensive list of "find|sort|cpio" at this time. see attached for a short list. it should give you an idea of using find, sort, and cpio. hth. -- peace out. in a world with out fences, who needs gates. sl6.3 linux tc.hago. g .
## cpio.tape v .2009.1115 #!/bin/sh # routines using cpio to write and read a scsi tape drive if [ $# = 0 ] ; then echo;echo " change to directory to be copied" echo " or where to dump tape.";echo echo " cpio.tape { (w)rite | (r)ead | (l)ist files }";echo fi # making a command line tape backup quick, easy, # and with out need of any special programs. # create a link from tape device to '/dev/tape'. # cd to top directory of path to back up when doing write. this way, when you # restore, you may restore files were ever you wish, as '/' is never implied. # =+= write, full backup; [w/ 5120 byte record] # **note** using 'grep -iv "\./proc"' eliminates '/proc' path if [ "$1" = "w" ] ; then find . -print | grep -iv "\./proc" | sort | \ cpio -oaBcv -O /dev/tape fi # =+= write, modified; [1 day old] # find . -mtime 1 -type f -print | cpio -oaBcv -O /dev/tape # =+= restore all; if [ "$1" = "r" ] ; then cpio -iBcdlmv -I /dev/tape fi # =+= restore a file; # if [ "$1" = "r" ] ; then # echo "path-filename" | cpio -iBcdlmv -I /dev/tape # fi # =+= view names of files stored; [builds an index file] # cpio -iBct -I /dev/tape [ > bkup.indx ] # or, for 'ls -l' type output; if [ "$1" = "l" ] ; then # "cpio -iBctv -I /dev/st0 > bkup.indx" "cpio -iBctv -I /dev/tape/scsi-nst > bkup.indx" fi # =+= run backup from cron; # 30 01 * * * find . -print | grep -iv "\./proc" | \ # sort | cpio -oaBcv -O /dev/tape # or; # 30 01 * * * 'script-file' # [where 'script-file' is any combination of _write_.] # =+= why cpio? # cpio is available on all systems, as is tar. # cpio will span multiple tapes, as will tar. # cpio will skip bad data and tell you, tar may not. # read 'man' for: cpio, cron, find, grep, sort. # =+= end.
-- users mailing list users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org