300x250 AD TOP

Search This Blog

Pages

Paling Dilihat

Powered by Blogger.

Wednesday, April 7, 2010

Simple Differential Backups using 7Zip

USE THIS AT YOUR OWN RISK!


I was looking at several desktop backup programs but I couldn't find a simple enough one that will just work, I wanted a link on my desktop so when I insert my thumb drive it will go over everything I backed up and do a simple differential backup.


Simple and quick.


So I decided to write a script, something simple, quick and secure.


7Zip was my first choice, so I decided to look up the command line parameters.


First I needed something that will give me file names in date time format, I've found this article written by Mark Yocom, I haven't looked at advanced batch files for ages, so thanks Mark!


for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
   for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (
        set FILENAME=basename-%%c-%%b-%%a-%%m%%n%%o%%p
   )
)




First, we generate the file names, the full and the differential date time based file name.

Then, we list the folders for backups.


Last, we check if the full file exists, if it doesn't we generate a full backup, otherwise, we generate a differential backup.


Full backup:


7z.exe a -p -mhe -ms=off -ssw -mx=7 -xr!*.vhd %fullbackupfilename% %backupfolders%

a - Add to archive
-p - Ask for password, I didn't want to put any passwords in the batch file, its not secure, but you can do that.
-mhe - Encrypt header, more secure.
-ms=off - disable solid, its less efficient, but its also less of a nightmare to restore.
-ssw - compress also open files
-mx=7 - level of compression, balance between compression ratio and speed, for me 7 is good, you may change that but you might not see too much of a difference.
-xr!*.vhd - I wanted to exclude all vhd files from my archive.


Differential backup:


7z.exe u -p -mhe -ms=off -ssw %fullbackupfilename%  %backupfolders% -xr!*.vhd -mx=9 -t7z -u- -up0q3r2x2y2z0w2!%diffbackupfilename%

u - Update archive
-t7z - specify the target of the differential file is 7z
-u- - disable any updates in the base archive.
-up0q3r2x2y2z0w2!%diffbackupfilename% - specifications in the documentation, to simplify, backup whatever changed, create anti-item for files that don't exist, add new files.

You can find the full script here.


For restoring from backup including the diff file, you restore both files to the same location, the differential file contains new, updated and anti-files, which are basically empty file names telling the program to delete existing file in that location.


Just remember, a backup is not worth anything if its not working, you're responsible for testing your backups every once in a while, if its important data, you might want to implement a verification procedure after every backup. 


USE THIS AT YOUR OWN RISK!

Tags:

Tuesday, April 6, 2010

Google like SQL Full Text Search Transformation

Have you ever tried to use SQL Full text search syntax? 
It could be a pain in the... you need to parse it and make sure there is no attempt to inject any sql, the parenthesis are opened and closed, quotes are closed if opened and I'm probably forgetting something.


Eric W. Bachtal wrote an article and a class that does it for you.


Give it a try, it made my life very easy.


I've also uploaded a copy to my repository in case the link ever go down.


Update: It should be noted that Jonathan Wood also implemented something similar, I haven't tested it though, next project then.
Tags: