SomaFM commercial free internet radio Powershell + 7zip + SQL Server backups

Paul Sturm

My notebook of discovered facts

Powershell + 7zip + SQL Server backups

I needed a way to shrink the backups in SQL Server 2005 (native compression doesn't exist until the 2008 version). 7zip compresses better than most anything, it's free (even for commercial use), its stable, and it's small. Powershell is my favorite tool builder. This is the result:

#set alias to 7zip - adjust path as necessary
set-alias sevenZip "c:\program files\7-zip\7z.exe"

#list of database filenames
$dbdirectories = "db1","db2","db3","db4"

$dbbackupDrive = "x:\"                              # this is where SQL Server stores its backups
$dbzdestination = "y:\7zipped_backups\"             # this is where we will store the 7z version

#Backups location
cd "$dbzdestination"                                # change directory 

#create some file masks based on date

$ybu = get-date (Get-Date).addDays(-1) -format "yyyyMMdd"    # this is the filename mask of yesterday's backups
$yz = get-date (Get-Date).addDays(-1) -format "yyyy.MM.dd"   # this is the filename mask of the zip destination
$yzr = get-date (Get-Date).addDays(-2) -format "yyyy.MM.dd"  # these are the day old 7zips (unused yet)
                                                             # I may want to remove older 7zips after copied offsite
                                                             
#$exclude1 = "-x!*.dif"                             # unused but could be appended to command 
#$exclude2 = "-x!*.7z"                              # unused but could be appended to command 

foreach ($dbdirectory in $dbdirectories)            # looping each db name in our list,
{  

    $backuppath = $dbbackupDrive + $dbdirectory + "\"            #build the path to the backup sources
    $backupfiles = $dbdirectory + "_backup_" + $ybu + "*.*"       #build the filename mask
    $input = $backuppath + $backupfiles                          #full path to source files (SQL Server's files)

    $outputfile = $dbdirectory + "_backup_" + $yz + ".7z"        #build the 7z filename (7zip file)

    cd "$dbzdestination$dbdirectory"               #change the path to the backup destination
    
    # command line switch descriptions (see http://dotnetperls.com/7-zip-examples)
    #   -t7z = 7zip type
    #   -v10m = split to 10 meg files
    #   -mmt = multithreading
    
    "7zip a -t7z -v10m -mmt=off $outputfile $input"               # echo out some progress    
    
    sevenZip a -t7z -v10m -mmt=off "$outputfile" "$input"         # 7zip them up

}

# we're all done, let's cleanup
Remove-Item Alias:sevenZip

Permalink | Comments (21) | Post RSSRSS comment feed

Comments

df

Sunday, February 07, 2010 5:27 PM

df

hi..

Perlite in Swimming Pool Filters

Sunday, February 07, 2010 6:48 PM

I can’t see clearly the codes, I don’t understand what was written in your site but I appreciated it a lot. SQL server is very popular to the people who usually using or working out about the SQL. I’m still working on it and thanks for sharing.

wow mage

Wednesday, February 17, 2010 1:00 PM

I've been browsing around looking for information like this forever, and I'm glad i finally found some.

emporio armani online

Thursday, February 18, 2010 11:56 PM

hmm.. very interesting .. thx for this tool .. try to use it

Carie Parcells

Friday, February 19, 2010 1:35 PM

Hello, You write some very informative blogs. I always check back here often to see if you have updated.

Motorcycle Helmet

Friday, February 19, 2010 3:47 PM

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

britt borden md

Saturday, February 20, 2010 1:02 AM

Do you have a spam problem  here; I also use Blog Engine, and I was wondering about your experiences; we have developed some good practices and we would like to exchange practices with others, please Email me if interested.

cheating quotes

Saturday, February 20, 2010 1:55 AM

Cool post thanks. Extremely interesting subject matter, will bookmark your site to see if you write more about in the future.

cheating girlfriend

Saturday, February 20, 2010 8:13 AM

Fantastic post thanks. Very remarkable topic, will bookmark your blog to see if you write further about in the future.

Brett Borden

Sunday, February 21, 2010 1:55 AM

This is my third visit to this blog. We are starting a brand new initiative in the same category as this blog. Your blog provided us with valuable information to work on. You have done a marvellous job.

watch alice in wonderland online

Sunday, February 21, 2010 3:05 AM

I’m unsure of my own stance on commenting. Sometimes I feel its watch shameless self-promotion for most people, but then at other times I feel watch somewhat guilty for consuming some fantastic content without contributing my thoughts to the topic.

britt borden

Sunday, February 21, 2010 7:04 AM

Have you had problems with spammers?  I also use Blog Engine and I have some great anti-spam techniques; please Email me if you are interested in an exchange of practices.

Burton Haynes

Sunday, February 21, 2010 4:31 PM

This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.

Leuchtreklame

Monday, February 22, 2010 2:00 AM

asmgermany stellt <a href=www.leuchtreklame365.com>Leuchtreklame</a> wie <a href=www.leuchtreklame365.com/.../a>, Messingbuchstaben, Aluminiumbuchstaben, Bronzebuchstaben, <a href=www.leuchtreklame365.com/outdoor-leuchtschilder>outdoor Leuchtschilder</a>

britt borden transverse foramen

Monday, February 22, 2010 1:36 PM

Do you have a spam problem  here; I also use Blog Engine, and I was speculating about your situation; we have developed some great techniques and we are looking to exchange thoughts with others, please Email me if interested.

britt borden

Monday, February 22, 2010 6:14 PM

This post was very well written, and it also contains a lot of useful facts. I appreciated your distinguished way of writing the post. You have made it easy for me to understand.

Burberry Mens Watch

Monday, February 22, 2010 9:47 PM

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well.

Dr. Britt Ekland Borden

Tuesday, February 23, 2010 6:58 AM

This is my second visit to this blog. We are starting a new initiative in the same niche as this blog. Your blog provided us with valuable information to work on. You have done a marvellous job.

britt borden

Wednesday, February 24, 2010 3:44 AM

Do you have a spam problem  here; I also use Blog Engine, and I was speculating about your experiences; we have developed some good practices and we are looking to exchange techniques with others, please Email me if interested.

britt borden john h stroger jr hospital

Wednesday, February 24, 2010 9:06 AM

This is a great web site.  Good fresh UI and very informative articles. I will be coming back soon, thanks for the great article.

britt borden

Wednesday, February 24, 2010 6:09 PM

This is my second visit to your blog. We are starting a brand new initiative in the same category as this blog. Your blog provided us with important information to work on. You have done a fantastic job.

Comments are closed