Making a simple script faster
By user12625760 on Aug 04, 2009
Many databases get backed up by simply stopping the database copying all the data files and then restarting the database. This is fine for things that don't require 24 hour access. However if you are concerned about the time it takes to take the back up then don't do this:
stop_database cp /data/file1.db . gzip file1.db cp /data/file2.db . gzip file2.db start_database
Now there are many ways to improve this using ZFS and snapshots being one of the best but if you don't want to go there then at the very least stop doing the “cp”. It is completely pointless. The above should just be:
stop_database gzip < /data/file1.db > file1.db gzip < /data/file2.db > file2.db start_database
You can continue to make it faster by backgrounding those gzips if the system has spare capacity while the back up is running but that is another point. Just stopping those extra copies will make life faster as they are completely unnecessary.