I have a script which periodically backs up a directory using the command "tar -czvf [name] [directory]" but my problem is that the script has recently been putting a lot of stress on the server (Minecraft SMP) and tends to lag players as it backs up, which recently has been taking nearly 5 minutes.

So I need to know if there's a way to control the GZip compression rate at the same time that it archives and backs up the files?

I understand that I can first tar the files and then GZip them separately with a different compression rate afterwards, but this would not work because it names the files with the current server time, which sometimes changes in between commands.

Any insight? Thanks ahead of time.

link|improve this question
1  
this isn't a programming question; it might be better on the power users or linux/unix stackexchange sites. – jcomeau_ictx Jun 4 '11 at 5:23
2  
I apologize, I only posted it here because it was part of a shell script.. I figured out my problem though, the simple fix was to put "GZIP=-[compression level]" immediately before the tar command like so: GZIP=-[compression level] tar -czvf [name].tar.gz [directory] – Alex Bennett Jun 4 '11 at 6:41
feedback

migrated from stackoverflow.com Jun 4 '11 at 13:19

This question came from our site for professional and enthusiast programmers.

2 Answers

Doing it in two steps is probably more portable. If you need a timestamp, store it first:

filename=/what/ever/backup-$(date +%Y%m%d%H%M%S).tar
tar cvf $filename ...
gzip -1 $filename

I'd also suggest you look into nice and ionice. They could help you lessen the effects of the backups on server responsiveness.

link|improve this answer
I actually solved it another way by using GZIP=-[compression level] tar -czvf [name].tar.gz [directory] in which I used 1 for the compression level, but I'll definitely give your method a try to make the backup names more uniform and hopefully lessen the lag even more by changing the priorities which is something that never crossed my mind before. Thanks a ton. – Alex Bennett Jun 4 '11 at 6:54
feedback

I often do something like this so when the tar process is done, I don't have to remember to gzip as it's all done on one line:

tar cvf - $nameOfDirOrFileToBeBackedUp | gzip -$compressionLevel > $backupLocation/$nameOfDirOrFileToBeBackedUp.tar.gz

This method works on older versions of tar that don't support gzip (Solaris 10 still doesn't).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown