|
The following is a sample script. It backs up selected files from a directory: #!/bin/bash # Script name: project1_backup # Description: Backs up project files into a subdirectory for file in proj1* do fback=project1/$file.bak if [ -f $fback ] then if [ $fback -nt $file ] then cp $file $fback echo `date` $file backed up >> backup.log fi else cp $file $fback echo `date` $file backed up >> backup.log fi done The script iterates through a list of filenames that begin with proj1. It checks whether the current file is newer than the existing backup file. If so, it copies the current file into the backup directory, giving it a .bak extension. Also, any current file that has not yet been backed up is copied into the backup directory. |
|