Backing Up and Restoring Your Data
We recommend backing up your database daily, so should you need to restore the database you always have the most current asset and help desk information.
Backing up the database can be automated by either using the SyAM Management Utilities to run the daily backup script or using Windows Scheduled Tasks.
Below is a script that you can use to backup the databases of Site Manager, Management Utilities and System Area Manager.
Copy the text below and update the highlighted areas based on your configuration, then save this as syamdailybackup.bat
Backing Up your Data
Previous Next
We recommend backing up your database daily, so should you need to restore the database you always have the most current asset and help desk information.
Backing up the database can be automated by either using the SyAM Management Utilities to run the daily backup script or using Windows Scheduled Tasks.
Below is a script that you can use to backup the databases of Site Manager, Management Utilities and System Area Manager.
Copy the text below and update the highlighted areas based on your configuration, then save this as syamdailybackup.bat
@ECHO OFF
REM syamserverbackup.bat
REM Database backup for:
REM SyAM System Area Manager
REM SyAM Management Utilities
REM SyAM Site Manager
REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Enable backup for a program by setting to 1.
REM If the program is not installed, set to 0.
SET backup_area_manager=1
SET backup_management_utilities=1
SET backup_site_manager=1
REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Specify backup directory. This must be on a local
REM drive, not a network share. The directory will be
REM created if it does not already exist.
SET budir=C:\syamserverbackup\
REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Backups older than this number of days will be removed.
REM If retention is set to 0, no backups will be removed.
REM In any case, backups of a database are not removed if
REM there is no current backup file for that database
REM with size greater than zero.
SET retention=5
REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Specify your SQL database instance.
SET dbinstance=.\SQLEXPRESS
REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++
REM Specify installation directory for System Area Manager.
SET amdir=C:\SyAM\
SET SITEDIR=C:\SiteManager
REM Append trailing slashes as required
IF DEFINED amdir IF NOT "%amdir:~-1%"=="\" SET amdir=%amdir%\
IF DEFINED budir IF NOT "%budir:~-1%"=="\" SET budir=%budir%\
FOR /f "tokens=2-8 delims=.:/ " %%a in ("%date% %time: =0%") DO SET DateTime=%%c-%%a-%%b_%%d-%%e-%%f
IF NOT EXIST %budir% (
mkdir %budir%
)
SET logname="syamserverbackup.log"
SET logfile=%budir%%logname%
IF EXIST %logfile% (
ECHO. >> %logfile%
)
ECHO Start backup %DateTime% >> %logfile%
IF %backup_area_manager% NEQ 1 (
ECHO No backup configured for System Area Manager >> %logfile%
GOTO mubackup
)
IF NOT EXIST %amdir%javadb\syamdb.h2.db (
ECHO System Area Manager database not found >> %logfile%
GOTO mubackup
)
ECHO Backing up System Area Manager database >> %logfile%
net stop smcentralmgr > nul 2>&1
net stop smwebsrv > nul 2>&1
net stop smdbsrv > nul 2>&1
copy %amdir%javadb\syamdb.h2.db %budir%syamdb-%DateTime%.h2.db > nul 2>&1
net start smdbsrv > nul 2>&1
net start smwebsrv > nul 2>&1
net start smcentralmgr > nul 2>&1
IF NOT EXIST %budir%syamdb-%DateTime%.h2.db (
ECHO System Area Manager backup failed, file does not exist >> %logfile%
GOTO mubackup
)
FOR %%A IN (%budir%syamdb-%DateTime%.h2.db) DO SET amsize=%%~zA
ECHO Size of System Area Manager backup is %amsize% >> %logfile%
IF %amsize% EQU 0 (
ECHO System Area Manager backup failed, file is empty >> %logfile%
GOTO mubackup
)
:mubackup
IF %backup_management_utilities% NEQ 1 (
ECHO No backup configured for Management Utilities >> %logfile%
GOTO smbackup
)
sqlcmd -S %dbinstance% -Q "select name from sys.databases" | find "syamutility" > nul
IF %ERRORLEVEL% EQU 1 (
ECHO Management Utilities database not found >> %logfile%
GOTO smbackup
)
sqlcmd -S %dbinstance% -Q "BACKUP DATABASE syamutility TO DISK='%budir%syamutility-%DateTime%.bak'" >> %logfile%
IF NOT EXIST %budir%syamutility-%DateTime%.bak (
ECHO Management Utilities backup failed, file does not exist >> %logfile%
GOTO smbackup
)
FOR %%A IN (%budir%syamutility-%DateTime%.bak) DO SET amsize=%%~zA
ECHO Size of Management Utilities backup is %amsize% >> %logfile%
IF %amsize% EQU 0 (
ECHO Management Utilities backup failed, file is empty >> %logfile%
GOTO smbackup
)
:smbackup
IF %backup_site_manager% NEQ 1 (
ECHO No backup configured for Site Manager >> %logfile%
GOTO cleanup
)
sqlcmd -S %dbinstance% -Q "select name from sys.databases" | find "syamdb" > nul
IF %ERRORLEVEL% EQU 1 (
ECHO Site Manager database not found >> %logfile%
GOTO cleanup
)
sqlcmd -S %dbinstance% -Q "BACKUP DATABASE syamdb TO DISK='%budir%syamdb-%DateTime%.bak'" >> %logfile%
xcopy /e /I %SITEdir%\TicketAttachments\*.* %budir%sitemgr-%DateTime%\TicketAttachments >> %logfile%
xcopy /e /H /I %SITEdir%\Knowledgebase\ArticleAttachments\* %budir%sitemgr-%DateTime%\Knowledgebase\ArticleAttachments >> %logfile%
IF NOT EXIST %budir%syamdb-%DateTime%.bak (
ECHO Site Manager backup failed, file does not exist >> %logfile%
GOTO cleanup
)
FOR %%A IN (%budir%syamdb-%DateTime%.bak) DO SET amsize=%%~zA
ECHO Size of Site Manager backup is %amsize% >> %logfile%
IF %amsize% EQU 0 (
ECHO Site Manager backup failed, file is empty >> %logfile%
GOTO cleanup
)
:cleanup
pause
IF %retention% LEQ 0 (
ECHO Cleanup of old backups is not configured >> %logfile%
GOTO end
)
REM delete backups of size zero
forfiles /p %budir% /m syamdb*.db /c "cmd /c if @fsize==0 del @file" > nul
forfiles /p %budir% /m syamutility*.bak /c "cmd /c if @fsize==0 del @file" > nul
forfiles /p %budir% /m syamdb*.bak /c "cmd /c if @fsize==0 del @file" > nul
REM rename old backups
forfiles /d -%retention% /p %budir% /m syamdb*.db /c "cmd /c rename @file old-@file" > nul
forfiles /d -%retention% /p %budir% /m syamutility*.bak /c "cmd /c rename @file old-@file" > nul
forfiles /d -%retention% /p %budir% /m syamdb*.bak /c "cmd /c rename @file old-@file" > nul
REM delete old backups unless no current backup exists
IF EXIST %budir%syamdb*.db (
DEL %budir%old-syamdb*.db > nul
)
IF EXIST %budir%syamutility*.bak (
DEL %budir%old-syamutility*.bak > nul
)
IF EXIST %budir%syamdb*.bak (
DEL %budir%old-syamdb*.bak > nul
)
REM remove sitemanager folder backups
echo - cleanning sitemgr
pause
cd /D %budir%
FOR /D %%a IN (site*) DO (
forfiles /P "%budir%\%%a" /S /M *.* /D -%retention% /C "cmd /C del @PATH"
cd /D %budir%\%%a
for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do rd /S /Q "%%i" > nul
cd /D %budir%
for /f "delims=" %%a in ('dir /s /b /ad ^| sort /r') do RD /S /Q %%a > nul
)
:end
ECHO Backup script completed >> %logfile%
EXIT
Your Backup Folder will contain the database backup .bak files and the folders containing the Ticket and Knowledgbase attachments.