0

Code snippets : SQL : Backup and FTP Database

-

When browsing repository of all scripts I did use in past, I found one which might be interesting. What this script does is:

  • Backups database to disk (name of database stored in @dbname, patch for backup stored in @archive_path, name of backup fine stored in @fname)
  • Compresses database backup using WinRAR (full command where to find WinRAR and how ot use it stored in @archive_cmd)
  • Generates set of commands for FTP client (series of xp_cmdshell commands redirecting output to F:\Backup\ftpcmds)
  • Uploads compressed backup to FTP server using command prompt FTP client command

I had that as small procedure executed automatically with SQL Server Agent. Script is for Microsoft SQL Server and I was running it on SQL Server 2000 and 2005. Here is code for that small procedure:

 

DECLARE @fname varchar(255)
DECLARE @fname_backup varchar(255)
DECLARE @fname_archive varchar(255)
DECLARE @archive_path varchar(255)
DECLARE @dbname varchar(255)
DECLARE @archive_cmd varchar(255)
DECLARE @put_cmd varchar(255)

SET @dbname = 'dbApplication'
SET @fname = @dbname + '_' + LTRIM(STR(DAY(GETDATE())))  + '.' + LTRIM(STR(MONTH(GETDATE()))) + '.' + LTRIM(STR(YEAR(GETDATE())))
SET @archive_path = 'F:\Backup\'
SET @fname_backup = @archive_path + @fname + '.BAK'
SET @fname_archive = @archive_path + @fname + '.RAR'
SET @archive_cmd = '"C:\Program Files\WinRAR\WinRAR.EXE" a ' + @fname_archive + ' ' + @fname_backup
SET @put_cmd = 'echo put ' + @fname_archive + '>> F:\Backup\ftpcmds'

PRINT @fname_backup
PRINT @fname_archive

BACKUP DATABASE @dbname TO DISK = @fname_backup WITH INIT

EXEC xp_cmdshell @archive_cmd
EXEC xp_cmdshell 'echo open 192.168.10.101> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'echo user dbupload>> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'echo password123>> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'echo cd DB_Backup>> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'echo bin>> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'echo ha>> F:\Backup\ftpcmds'
EXEC xp_cmdshell @put_cmd
EXEC xp_cmdshell 'echo bye>> F:\Backup\ftpcmds'
EXEC xp_cmdshell 'ftp -d -i -n -s:F:\BACKUP\ftpcmds'

I hope that will be handy for someone to automate databsae backups and transfers.

4

Config snippets : OpenSSL for Windows can’t find openssl.cfg

-

Little issue with OpenSSL for Windows came out recently when I tried to create certificate request. Just after installation when tried to generate cert request got error message:

WARNING: can't open config file: /usr/local/ssl/openssl.cnf
Unable to load config info from /usr/local/ssl/openssl.cnf

Reason was that by default OpenSSL couldn’t find configuration file (even if it was located in same folder as excutable file).

So, to fix it just set environmental variable with information where openssl.cfg file is located:

set OPENSSL_CONF=c:\OpenSSL-Win32\bin\openssl.cfg

You can consider adding this to system environmental variables.

1

Tips&Tricks : How to skip Autologon in Windows XP

-

As I had to fight with WIndows XP Autologon (we have it on many computers which are used for example for CCTV), I think can write down one more quick tips how to skip Autologon feature and use different account to access computer (for example to install Windows Updates).

So, situation I was dealing with was computer with Windows XP, connected to Active Directory domain with Autologn feature enabled. After computer started I’ve seen welcome dialog and after pressed ctrl-alt-del autologn procedure kick in and login to computer with restricted account. How to skip autologon process and be able to enter different username and password?

(more…)

0

Windows Registry : Autologon in Windows XP

-

Again one of those things which I forget when is needed. Autologon in Windows XP. Funny enough is the fact that each time I’m looking for this information is when I want to prevent Windows XP from auto logon and trying to disable that in registry using remote access from Registry Editor.

Fortunately Microsoft prepared full detailed description, so now I can write down in my scratchpad for future reference instead of using Google each time I need that 😀

(more…)

0

Code snippets : List all logical disks in Windows 7 Command Prompt

-

Recently I was wondering how to list all available drives in Windows 7 PE Command Prompt. That happened to me when stuck in PXE boot command prompt window trying to find out what letter is assigned to USB stick I just plugged in. It looks like it’s not quite straightforward activity 🙂

(more…)

0

Configuring room-type resource mailbox on Exchange 2007 in auto accept mode

-

Mailboxes created for conference rooms (on Exchange 2007 Recipient Type : Room Mailbox) by default has disabled auto accept for calendar appointments. That causes issue when people trying to book room as all appointments show as tentative and manual interaction/accept is required. In order to streamline process and make it more handy for people (in case nobody is assigned to control room bookings) you can enable auto accept feature, so all appointments will be accepted automatically. To do that use PowerShell:

(more…)