• Here is a simple example.

    First file is the .sql script. It is invoked using SQLCMD in a batch file. Create one of these .sql files for each of the databases that you want to back up, including the system databases (master, model, msdb).

    Then create a .bat file and have a line in it invoking SQLCMD for each of the database files that you want to run.

    MyDatabase_backup_script.sql

    ==========================

    DECLARE @fn nvarchar(256),

    @dbname nvarchar(50),

    @stmt nvarchar(4000),

    @path nvarchar(4000)

    SET @dbname = 'MyDatabase'

    SET @path = 'c:\SQLBackups\' + @dbname + '\'

    SET @fn = @path + @dbname + '_backup_' +

    CONVERT(nchar(8),getdate(), 112) +

    right(N'0' + rtrim(CONVERT

    (nchar(2), datepart(hh, getdate()))), 2) +

    right(N'0' + rtrim(CONVERT

    (nchar(2), datepart(mi, getdate()))), 2) +

    N'.bak'

    --SELECT @fn

    SET @stmt = 'BACKUP DATABASE '

    + QUOTENAME(@dbname, '[') + ' to disk

    = ''' + @fn + ''''

    --SELECT @stmt

    EXEC (@stmt)

    Database_backups.bat

    ==========================

    sqlcmd -S (local)\SQLEXPRESS -E -i C:\SQLEE_Backups\MyDatabase_backup_script.sql -o C:\SQLBackupLogs\MyDatabase_backuplog.txt

    Have one of these lines for each database to back up, then just schedule the .bat file to run every night, say at 1am.

    The (local) part runs on the local machine, where the batch file is ran. This could be changed to the specific server or pc name if needed.

    The -o text file is the output log file of the run. It will show any errors if it encounters any. I would keep the name in a format that will just overwrite itself so you don't have to worry about multiple versions to clean up. Note that this will be an issue with the database backups, since the script backs it up to a file name with a date stamp on it.

    Here is an example of a .sql script to do a tranlog backup. Again, just have a .sql file for each database that you need to do tranlog backups for, and put them in a separate .bat file and set to run multiple times per day.

    Tranlog backup script

    ==================================

    DECLARE @fn nvarchar(256),

    @dbname nvarchar(50),

    @stmt nvarchar(4000),

    @path nvarchar(4000)

    SET @dbname = 'MyDatabase'

    SET @path = 'c:\SQLBackups\' + @dbname + '\tlogs\'

    SET @fn = @path + @dbname + '_backup_' +

    CONVERT(nchar(8),getdate(), 112) +

    right(N'0' + rtrim(CONVERT

    (nchar(2), datepart(hh, getdate()))), 2) +

    right(N'0' + rtrim(CONVERT

    (nchar(2), datepart(mi, getdate()))), 2) +

    N'.trn'

    --SELECT @fn

    SET @stmt = 'BACKUP LOG '

    + QUOTENAME(@dbname, '[') + ' to disk

    = ''' + @fn + ''''

    --SELECT @stmt

    EXEC (@stmt)

    Hope it helps.