Skip to content

Instantly share code, notes, and snippets.

@billerby
Created November 17, 2011 13:27
Show Gist options
  • Save billerby/1373123 to your computer and use it in GitHub Desktop.
Save billerby/1373123 to your computer and use it in GitHub Desktop.
Alfresco offline backup for Windows
@ECHO OFF
REM Alfresco backup script
REM Version 1.01, Updated: 2011-11-17
REM By Erik Billerby, billerby[-at-]gmail.com
REM Performs a full offline backup of Alfresco.
REM Location where 7-Zip is installed on your computer.
REM The default is in a folder, '7-Zip' in your Program Files directory.
SET InstallLocationOf7Zip=C:\Program Files\7-Zip
SET ALF_DATA_PATH=F:\alfresco
SET ALF_DATA_DIR_NAME=alf_data
SET BACKUP_DIR=F:\alfresco\backups
SET MYSQL_USERNAME=root
SET MYSQL_PASSWORD=pttbjbh
SET DATABASE_NAME=alf_tomcat
SET MYSQL_HOST=10.10.25.134
REM +-----------------------------------------------------------------------+
REM | Do not change anything below here unless you know what you are doing. |
REM +-----------------------------------------------------------------------+
REM Usage variables.
SET exe7Zip=%InstallLocationOf7Zip%\7z.exe
set MYSQLDUMP=D:\mysqlclient\bin\mysqldump.exe
SET DAYS_TO_SAVE_ORPHANED_CONTENT=14
SET DAYS_TO_SAVE_BACKUP_ARCHIVES=7
REM Delete orphaned content older than two weeks
cd %ALF_DATA_PATH%\%ALF_DATA_DIR_NAME%
ECHO deleting orphaned content older than %DAYS_TO_SAVE_ORPHANED_CONTENT% days
forfiles /p %ALF_DATA_PATH%\%ALF_DATA_DIR_NAME%\contentstore.deleted /s /m *.* /d -%DAYS_TO_SAVE_ORPHANED_CONTENT% /C "cmd /c del @path"
FOR /f "delims=" %%i IN ('date /t') do SET "ddd=%%i"
SET d1=%ddd:~0,4%
SET d2=%ddd:~5,2%
SET d3=%ddd:~8,2%
SET DATE=%d1%%d2%%d3%
SET FDIR=%d1%-%d2%-%d3%
REM first stop the tomcat server
net stop "Alfresco Server"
REM backup the alfresco database
md "%BACKUP_DIR%\%FDIR%"
ECHO backing up the alfresco mysql database...
call "%MYSQLDUMP%" -u %MYSQL_USERNAME% -p%MYSQL_PASSWORD% %DATABASE_NAME% --default-character-set=latin1 -N --host=%MYSQL_HOST% > "%BACKUP_DIR%\%FDIR%\%DATE%.sql"
cd %BACKUP_DIR%
mkdir %FDIR%\%ALF_DATA_DIR_NAME%
ECHO backing up the alfresco data directories
xcopy %ALF_DATA_PATH%\%ALF_DATA_DIR_NAME% %BACKUP_DIR%\%FDIR%\%ALF_DATA_DIR_NAME% /E /Q /I
ECHO Compressing backed up files. (New window)
REM Compress files using 7-Zip in a lower priority process.
START "Compressing Backup. DO NOT CLOSE" /belownormal /wait "%exe7Zip%" a %BACKUP_DIR%\backup_%FDIR%.zip %BACKUP_DIR%\%FDIR%\"
ECHO Done compressing backed up files.
ECHO.
REM remove the orignial folder.
rmdir /s /q %BACKUP_DIR%\%FDIR%
ECHO delete previous backup archives older than %DAYS_TO_SAVE_BACKUP_ARCHIVES% days...
forfiles /p %BACKUP_DIR% /m *.* /d -%DAYS_TO_SAVE_BACKUP_ARCHIVES% /s /c "cmd /c del @path"
REM start the tomcat server
net start "Alfresco Server"
ECHO Finished!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment