Difference between revisions of "Scheduling Backup"
From IMSMA Wiki
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{Note | It is advised to plan when to take the backup carefully so the usage of IMSMA is not hindered and the backup is successful. If the backup is scheduled during the night then it is important to very the next day that the backup was completed successfully. }} |
+ | {{Warning | This script '''only''' takes backup of the database and the attachments.}} | ||
+ | |||
+ | <ol> | ||
+ | <li> It is strongly recommended to '''[[Shutdown IMSMA Server | shutdown]]''' the IMSMA server before the backup is starting. | ||
+ | <li>Modify the following script by replacing ''xyz'' at '''SIX''' places with the folder where you would like the backup folder to be created. | ||
+ | <pre> | ||
+ | :: IMSMA backup via bat file | ||
+ | @echo off | ||
+ | @echo Backing up the database. This may take awhile, do not close this window. | ||
+ | :: C:\xyz is the folder where you want the backups to be created. The folder must exists before the script is started. | ||
+ | :: The user starting the Task in the Windows scheduler must have read/write access to the folder. | ||
+ | c:\imsmang\pgsql\bin\pg_dump -U imsma > C:\xyz\dump.sql | ||
+ | @echo Creating folder | ||
+ | :: Creates a folder with the date as a timestamp, similar to the backups done in IMSMA. Then moves the dump.sql to it. | ||
+ | for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a | ||
+ | set datestamp=%dt:~0,8% | ||
+ | set timestamp=%dt:~8,6% | ||
+ | echo datestamp: "%datestamp%" | ||
+ | echo timestamp: "%timestamp%" | ||
+ | set YYYY=%dt:~0,4% | ||
+ | set MM=%dt:~4,2% | ||
+ | set DD=%dt:~6,2% | ||
+ | set HH=%dt:~8,2% | ||
+ | set Min=%dt:~10,2% | ||
+ | set Sec=%dt:~12,2% | ||
+ | set foldername=Backup_%YYYY%_%MM%_%DD%_%HH%_%Min%_%Sec% | ||
+ | mkdir c:\xyz\%foldername% | ||
+ | move c:\xyz\dump.sql c:\xyz\%foldername%\ | ||
+ | @echo Copying the attachments | ||
+ | :: uses xcopy to copy files from server destination to backup destination. | ||
+ | :: /e Copies all subdirectories, even if they are empty] | ||
+ | :: /h Copies hidden/system files | ||
+ | :: /q suppresses output messages | ||
+ | mkdir c:\xyz\%foldername%\server\attachments | ||
+ | xcopy C:\IMSMAng\server\attachments c:\xyz\%foldername%\server\attachments /e /h /q | ||
+ | @echo Done. | ||
+ | </pre> | ||
+ | |||
+ | <li>Save it with name ''runIMSMAbackup.bat''. Do '''not''' save it in the ''C:\IMSMAng'' folder. | ||
<li>Schedule a task in the Operating System's Task scheduler. The following steps are done with Windows 7, follow those steps: | <li>Schedule a task in the Operating System's Task scheduler. The following steps are done with Windows 7, follow those steps: | ||
− | + | ||
<li>Go to Control Panel → Administrative Tools → Task Scheduler</li> | <li>Go to Control Panel → Administrative Tools → Task Scheduler</li> | ||
[[Image:Windows Scheduler.png|center|600px]] | [[Image:Windows Scheduler.png|center|600px]] | ||
Line 9: | Line 48: | ||
<li>Next, refine recurrence criteria (e.g. time of the day) and click '''Next'''.</li> | <li>Next, refine recurrence criteria (e.g. time of the day) and click '''Next'''.</li> | ||
<li>In the next window, select '''Start a Program''' and click '''Next'''.</li> | <li>In the next window, select '''Start a Program''' and click '''Next'''.</li> | ||
− | <li>Browser to the previously created script, e.g. C:\runIMSMAbackup.bat Click '''Next''' and then '''Finish'''.</li> | + | <li>Browser to the previously created script, e.g. C:\backups\runIMSMAbackup.bat Click '''Next''' and then '''Finish'''.</li> |
</ol> | </ol> | ||
− | |||
The {{IMSMANG}} backup should now start at the specified time. <br/> | The {{IMSMANG}} backup should now start at the specified time. <br/> | ||
[[Image:Scheduled bkp.png|center|800px]] | [[Image:Scheduled bkp.png|center|800px]] | ||
− | It is | + | It is also possible to '''[[Start-up IMSMA Server | start-up the IMSMA Server]]''' with a bat-file. |
− | [[ | + | {{NavBox Manage Information}} |
− | {{NavBox | ||
[[Category:NAA]] | [[Category:NAA]] |
Latest revision as of 09:47, 17 October 2017
This script only takes backup of the database and the attachments. |
- It is strongly recommended to shutdown the IMSMA server before the backup is starting.
- Modify the following script by replacing xyz at SIX places with the folder where you would like the backup folder to be created.
:: IMSMA backup via bat file @echo off @echo Backing up the database. This may take awhile, do not close this window. :: C:\xyz is the folder where you want the backups to be created. The folder must exists before the script is started. :: The user starting the Task in the Windows scheduler must have read/write access to the folder. c:\imsmang\pgsql\bin\pg_dump -U imsma > C:\xyz\dump.sql @echo Creating folder :: Creates a folder with the date as a timestamp, similar to the backups done in IMSMA. Then moves the dump.sql to it. for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a set datestamp=%dt:~0,8% set timestamp=%dt:~8,6% echo datestamp: "%datestamp%" echo timestamp: "%timestamp%" set YYYY=%dt:~0,4% set MM=%dt:~4,2% set DD=%dt:~6,2% set HH=%dt:~8,2% set Min=%dt:~10,2% set Sec=%dt:~12,2% set foldername=Backup_%YYYY%_%MM%_%DD%_%HH%_%Min%_%Sec% mkdir c:\xyz\%foldername% move c:\xyz\dump.sql c:\xyz\%foldername%\ @echo Copying the attachments :: uses xcopy to copy files from server destination to backup destination. :: /e Copies all subdirectories, even if they are empty] :: /h Copies hidden/system files :: /q suppresses output messages mkdir c:\xyz\%foldername%\server\attachments xcopy C:\IMSMAng\server\attachments c:\xyz\%foldername%\server\attachments /e /h /q @echo Done.
- Save it with name runIMSMAbackup.bat. Do not save it in the C:\IMSMAng folder.
- Schedule a task in the Operating System's Task scheduler. The following steps are done with Windows 7, follow those steps:
- Go to Control Panel → Administrative Tools → Task Scheduler
- In the Task Scheduler interface, click on Create Basic Task...
- In the Create Basic Task Wizard, provide a name, e.g. IMSMA Backup and an optional description. Click Next.
- In the next window, specify the required recurrence (daily, weekly, etc.) and click Next.
- Next, refine recurrence criteria (e.g. time of the day) and click Next.
- In the next window, select Start a Program and click Next.
- Browser to the previously created script, e.g. C:\backups\runIMSMAbackup.bat Click Next and then Finish.
The IMSMANG backup should now start at the specified time.
It is also possible to start-up the IMSMA Server with a bat-file.
|