I thought I'd share my little scheduled task for backing up the MediaPortal installation, settings, and SQLExpress database using WinRar.
The attached zip contains all of the necessary files. Extract the files into a folder on your hard drive and follow the instructions:
The backup jobs get named as such: "MediaPortalBackup (2008.04.22).rar". If you don't like this, you can change the format by modifying the "BackupName" and "DateFormat" SET variables in the .bat file. Just be careful as it may break the database backup file insertion (database backup is added using another call to Winrar using the generated date for filename. If too much time passes, the database backup will be in a newly generated rar).
Old backups are deleted automatically when this batch file is run. You can specify how long to keep backups by setting the "DaysToKeepBackups" variable.
Updates:
2008.04.22
- incorporated the deletion of old backup archives using the ForFiles.exe tool (thanks uggabugga)
- added -dh switch to the Winrar command to attempt open (shared) file archiving
2008.04.23
- added documentation to batch file
- added self-describing variable names
2008.04.23 - 14:30
- added MS SQL Express database backup support
- modified MediaPortalDirs.txt paths to account for more readable base paths in the backup archive
- added the -ep1 switch to turn off full path inclusion in the rar
- changed the date format to a "daily" format to allow for database backup to be inserted into the archive. If the backup took over 1 minute, a new archive was created with the database instead of including it in the current backup archive.
2008.05.06
- Added set variables in main MediaPortalBackup.bat for database name and backup path/filename
- Removed the hard-coding of paths for SQL backup location, database name, etc
- Upgrade to Winrar 3.71 didn't like the database backup file insertion using -n"filepath". Took out -n and just used the path to file to fix
The attached zip contains all of the necessary files. Extract the files into a folder on your hard drive and follow the instructions:
- MediaPortalDirs.txt - tells WinRar which directories to backup
- Add paths you wish to include in the backup archive to separate lines in this file.
Warning: I do not advise adding your MSSQL or MySQL paths to this file. Database backups using this method are very prone to errors as they are constantly being written.
- Add paths you wish to include in the backup archive to separate lines in this file.
- MediaPortalExcludes.txt - tells WinRar which directories / files to exclude from the backup (currenlty ignores log directories)
- Add paths (including wildcards) you wish to exclude from the backup archive to separate lines in this file
- MediaPortalBackup.bat - This file contains the command that runs WinRar using the above .txt files as input.
- Change the SET variables in this .bat file to paths appropriate for your system.
- RunMSSQLScript.bat - This file runs SQLCMD.EXE from the SQL Express installation to execute a sql script.
- This can be run by itself by passing in the name of the sql script file to run (ex. "MediaPortal MSSQL Database Backup.bat" "D:\Backup\MediaPortal SQLExpress Backup.sql")
- Change the SET variables in this .bat file for your SQLExpress username and password or backup will not work.
- MediaPortal SQLExpress Backup.sql - This file contains the SQL BACKUP command to backup the MediaPortal database.
- MediaPortal Backup.job - This is the Scheduled Task job.
- Drag the .job file into your Scheduled Tasks window (open Control Panel -> Scheduled Tasks).
- Change the working directory of the scheduled task to the path where your MediaPortalBackup.bat lives.
- Set the permissions and schedule appropriate for your system.
- ForFiles.exe - Windows resource kit utility that allows the batch file to delete old archives based on date
- Note: ForFiles.exe comes with Windows Server 2003 and Vista. These versions use the "/" switch notation versus the "-" switch notation. The ForFiles.exe found in the Win98 resource kit and other location on the net claiming to be from the Windows 2000 resource kit use the "-" switch notation. Using the incorrect switch notation depending on which version you have can cause the archive deletion to fail.
The backup jobs get named as such: "MediaPortalBackup (2008.04.22).rar". If you don't like this, you can change the format by modifying the "BackupName" and "DateFormat" SET variables in the .bat file. Just be careful as it may break the database backup file insertion (database backup is added using another call to Winrar using the generated date for filename. If too much time passes, the database backup will be in a newly generated rar).
Old backups are deleted automatically when this batch file is run. You can specify how long to keep backups by setting the "DaysToKeepBackups" variable.
Updates:
2008.04.22
- incorporated the deletion of old backup archives using the ForFiles.exe tool (thanks uggabugga)
- added -dh switch to the Winrar command to attempt open (shared) file archiving
2008.04.23
- added documentation to batch file
- added self-describing variable names
2008.04.23 - 14:30
- added MS SQL Express database backup support
- modified MediaPortalDirs.txt paths to account for more readable base paths in the backup archive
- added the -ep1 switch to turn off full path inclusion in the rar
- changed the date format to a "daily" format to allow for database backup to be inserted into the archive. If the backup took over 1 minute, a new archive was created with the database instead of including it in the current backup archive.
2008.05.06
- Added set variables in main MediaPortalBackup.bat for database name and backup path/filename
- Removed the hard-coding of paths for SQL backup location, database name, etc
- Upgrade to Winrar 3.71 didn't like the database backup file insertion using -n"filepath". Took out -n and just used the path to file to fix