Jump to content
Sign in to follow this  
Guest Vriendje

Back-up log file

Recommended Posts

Guest Vriendje

Hi,

 

Every night i use a bash scritpt to backup up my files form Drive A to Drive B.

Also there will be created a log file.

In this log file i like to see some info about a directory.

 

For example:

 

I start this command before the backup on my Freenas 7.x

echo " Web - Files :`find $SOURCE_WEB_F -type f | wc -l`" " /`find $DEST_WEB_F -type f |wc -l`" >>$LOG

After the backup i run this line again so i can see that all the files are on the backup disk

 

So what i like is the info after the backup in one line

 

Backup files - Source files - Files after backup

web 200 300 300

 

I like it this way but how can i see this info in one line after the backup (in the log file) :unsure: ??

Thanks for helping.

 

Vriendje

Edited by Vriendje

Share this post


Link to post
Share on other sites

I’m not sure I understand. Given the knowledge you seem to have with scripting, what I’m going to write somehow seems too simple…

So you have a script that is responsible for the backup, and you execute the same command at the start and at the end of the backup. The first occurrence gives “S0/D0â€, and the second gives “S1/D1â€, and you’d prefer instead “D0 S1 D1†on one line at the end. The logical way, in my opinion, would be to store D0 in a variable and then print everything at the end, like this (I assume bash as the shell):

D0=$(find "$DEST_WEB_F" -type f -print | wc -l)
… do the backup …
printf 'Backup files - Source files - Files after backup\nweb %d - %d - %d\n' \
 $D0 \
 $(find "$SOURCE_WEB_F" -type f -print | wc -l) \
 $(find "$DEST_WEB_F" -type f -print | wc -l) >>"$LOG"

Yves.

 

By the way, if you have a lot of files, “find … -printf . | wc -L†is slightly more efficient than “find … -print | wc -lâ€

Edited by theYinYeti

Share this post


Link to post
Share on other sites
Guest Vriendje

Thanx theYinYeti

 

I'm not that good with scripting. I know it has something to do with the DO command but i never used it.

So this was complete new for me. I can read it and i understand, but i never knew how to make one by myself:-)

 

Thanx, I think this is what i'm looking for.

 

I also will try -printf command.

 

Vriendje

 

Update:

 

Still have a little problem

 

I have more directories to check before and after the backup.

 

------

echo " Workstation - Files :`find $SOURCE_WRKST_F -type f | wc -l`" " /`find $DEST_WRKST_F -type f |wc -l`" >>$LOG

echo " Shared - Files :`find $SOURCE_SHARED_F -type f | wc -l`" " /`find $DEST_SHARED_F -type f |wc -l`" >>$LOG

echo " Web - Files :`find $SOURCE_WEB_F -type f | wc -l`" " /`find $DEST_WEB_F -type f |wc -l`" >>$LOG

echo " Pictures - Files :`find $SOURCE_PIC_F -type f | wc -l`" " /`find $DEST_PIC_F -type f |wc -l`" >>$LOG

echo " Movies - Files :`find $SOURCE_MOVIES_F -type f | wc -l`" " /`find $DEST_MOVIES_F -type f |wc -l`" >>$LOG

------

 

How can i check this before and after the backup with a do command?

 

btw when i start the script you wrote i see a zero?

 

web 756 - 756 - 0 <- It looks like he does not start the $(find "$SOURCE_WEB_F" -type f -print | wc -l) \

Even if change it to DEST_WEB_F it still returns a 0

 

Thanx for helping again!

Edited by Vriendje

Share this post


Link to post
Share on other sites

Vriendje, there is no DO command :-) I wrote D0 (dee zero, which stood for Destination at time T0), which is a variable, inside of which is stored (“=â€) a value which is the result of a command (“$(…)†notation is equivalent to the “`…`†notation but can be nested).

 

To do what you asked, you would write your script like this:

for d in WRKST SHARED WEB PIC MOVIES; do
   eval D0_$d=$(find "$DEST_${d}_F" -type f -printf . | wc -L)
done

… do the backup …

printf '\tBackup files\tSource files\tFiles after backup\n' >>"$LOG"
for d in WRKST SHARED WEB PIC MOVIES; do
   eval printf '%s\t%d\t%d\t%d\n' \
       \$D0_$d \
       $(find "$SOURCE_${d}_F" -type f -printf . | wc -L) \
       $(find "$DEST_${d}_F" -type f -printf . | wc -L) >>"$LOG"
done

Yves.

Edited by theYinYeti

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...