Home > OS >  With the shell how effectively the batch backup directory of images
With the shell how effectively the batch backup directory of images

Time:10-08

I wrote a script file, need to back up a directory of all the image files, the new image file directory at any time, my needs are: backup the image in the original directory delete;
It is part of the script I wrote:
CD $SOURCEDIR
The find | sed '1 d & gt; $SCRIPTDIR/filelist. TXT
For I ` cat in $SCRIPTDIR/filelist. TXT `
Do
If [! - d $I]
Then
Echo "start backup $I to $$SERVERNAME_ORCPICBAK_ BACKUPDIR/{$DATEDAY}. ZIP" & gt;> $SCRIPTDIR/logs. The log
Zip $BACKUPDIR/${SERVERNAME} _ORCPICBAK_ ${DATEDAY}. Zip $I & gt;> $SCRIPTDIR/logs. The log 2 & gt; & 1
If [$? - eq 0]
Then
Echo "backup $I Success, start the delete $I $SOURCEDIR from" & gt;> $SCRIPTDIR/logs. The log
Rm - rf $I
The else
Echo "file $I backup fail!!!!!! "& gt;> $SCRIPTDIR/logs. The log
Fi
Fi
The done
The above script in the execution of the moment to save the original image files in the directory as a temporary file filelist. TXT, I only to the filelist. TXT save file backups, delete, and shall not affect the new image file,

If the $SOURCEDIR directory exists thousands of images, the backup script efficiency is very low, finish backup will take me several hours at a time, the delay in the pictures on the backup of the, excuse me what method under the premise of meet my needs to improve efficiency?

CodePudding user response:

I tried to amend the zip back up into the tar are nearly the same efficiency, too low!

CodePudding user response:

Have a good way: first compression, and then follow up files from the zip to delete the original file:
The find./-name "*.jpg" | xargs zip temp. Zip
Then according to the temp. The contents of the ZIP file to the original directory delete backup image files, a huge increase in efficiency
  • Related