Backup Portales DNN y SQL

Ponemos el siguiente bat (copia_all.bat) en una carpeta por ej. C:\Users\Administrator\Documents\otrastareas\

Programamos el backup mediante el scheduler para cada dia a las 3 de la mañana

@REM Seamonkey’s quick date batch (MMDDYYYY format)
@REM Set ups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY

@ECHO OFF
SETLOCAL

@REM FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
@REM FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
@REM FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
@REM FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
@REM SET date=%mm%%dd%%yyyy%
set date=%DATE:/=%

set directory_of_this_script=C:\Users\Administrator\Documents\otrastareas\
set directory_tmp=C:\Users\Administrator\Documents\otrastareas\tmp\
set backup_destination=C:\backups\
set backup_origin=C:\HostingSpaces\
set instance_sql=.\SQLEXPRESS

REM Delete the previous backups, only the last backup here and download daily for FTP
del /Q /F  %backup_destination%*.7z

REM Build a list of databases to backup
SET DBList=%directory_tmp%SQLDBList.txt
SET FOLDERList=%directory_tmp%FOLDERList.txt
dir %backup_origin% /AD /B > "%FOLDERList%"
SqlCmd -E -S %instance_sql% -h-1 -W -Q "SET NoCount ON; SELECT Name FROM master.dbo.sysDatabases WHERE [Name] NOT IN ('master','model','msdb','tempdb')" > "%DBList%"

REM Backup each database, prepending the date to the filename
FOR /F "tokens=*" %%I IN (%DBList%) DO (
    ECHO Backing up database: %%I
    SqlCmd -E -S %instance_sql% -Q "BACKUP DATABASE [%%I] TO Disk='%directory_tmp%%date%_%%I.bak'"
    7za a -r %backup_destination%%%I_SQL_%date%.7z %directory_tmp%%date%_%%I.bak
    del %directory_tmp%%date%_%%I.bak
    
ECHO.
)

REM Backup each folder,
FOR /F "tokens=*" %%I IN (%FOLDERList%) DO (
    ECHO Backing up folder: %%I
    7za a -r %backup_destination%%%I_%date%.7z %backup_origin%%%I\
ECHO.
)

REM Clean up the temp file
IF EXIST "%DBList%" DEL /F /Q "%DBList%"
IF EXIST "%FOLDERList%" DEL /F /Q "%FOLDERList%"

ENDLOCAL

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Copyright 2018 Javier Antó | Javi