Results 1 to 4 of 4
I am creating a backup script with the cp command
I was piping the output of the command using >> to a log file
But my log file grows big ...
- 08-23-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
cp -drufv and keep a count of files copied
I am creating a backup script with the cp command
I was piping the output of the command using >> to a log file
But my log file grows big quickly that way. I would rather just log the # of files copied as a way to ensure the backup is working.
I'm trying to figure out how to count the # of files copied using the verbose output from cp
like:
echo "backup started" >> logfile
cp -drufv * /backups >> count the number of files here = $count
echo "back finished" >> logfile
echo "$count files coped" >> logfile
exit 0
thanks
- 08-23-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
do the counting before the copy, using wc.
- 08-23-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
Thanks for the suggestion but I've never used wc and couldn't figure out the syntax after a few minutes of tinkering.
But that got me thinking about grep and here is what I came up with:
#!/bin/sh
#
#####written by lee Aug 2008
#
#####clear backups log
#
echo " " > /Users/lee/system_backup/backups_log.txt
#
#####clear file log
#
echo " " > /Users/lee/system_backup/file_log.txt
#
#
#
#####begin backups
#
#####lee backups
#
cd /Users/lee
cp -drufv * /Volumes/backups/lee/ >> /Users/lee/system_backup/file_log.txt
#
#####dana backups
#
cd /Users/dana
cp -drufv * /Volumes/backups/dana/ >> /Users/lee/system_backup/file_log.txt
#
#####pics backups
#
cd /Volumes/storage/pics/
cp -drufv * /Volumes/backups/pics/ >> /Users/lee/system_backup/file_log.txt
#
#
#####end backups
#
#
#
#####stamp end time and report number of files copied
#
echo "The most recent System Backup completed on" `date` "and" `grep -c -e '->' /Users/lee/system_backup/file_log.txt` "files were copied." >> /Users/lee/system_backup/backups_log.txt
#
#####done
#
exit 0
notice that I decided to clear both logs (mandatory for the file log so the count will be meaningful) at the begining. I had been using a running backup log before.
- 08-24-2008 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
