Windows PowerShell script for archiving RedMine Turnkey Hyper-V over ssh

Initial data


Get a backup of the RedMine database and files smaller than the whole Hyper-V image.

You need to know a little about PowerShell and PuTTY (although I recommend WinSCP – visually edit files and walk around the directory).

After debugging and adjusting for your additional needs (for example, exclude large Git directories), shove it into the standard scheduler Windows (do not forget about specifying the working directory).


After the number of the item, the System in which we are performing the action.

one. Windows. Install OpenSSH.Client, execute PowerShell

Add-WindowsCapability -Online -Name OpenSSH.Client*

2. Windows. Generate shh key, execute PowerShell

cd c:Users[UserName].ssh
ssh-keygen -t rsa -b 4096 -C ""

[UserName] – the name of the current user.

Catalog c: Users [UserName] .ssh usually hidden and / or systemic. If there is no catalog, create it first. – e-mail of the current user.

3. Redmine… Content from c: Users [UserName] .ssh append file (add new line) root / .ssh / authorized_keys

Catalog root / .ssh / authorized_keys usually hidden and / or systemic.

4. Windows. Establishing the first connection, execute PowerShell

ssh root@

root – RedMine user – IP Hyper-V where RedMine is deployed

PowerShell will ask you to accept the connection, dial yes and press Enter, if everything is done correctly, you will no longer have to enter the password when connecting via ssh.

5. Windows. Create a file StartBackUp.ps1 with content in the user’s working directory (RedMine data will be backed up to this directory)

#Текущая дата

#Создаем (удаляя предыдущий) скрипт арихивации
Write-Host "=====================$DateStr======================"
$FileName = "BackUpScript.ps1"
if (Test-Path $FileName) 
  Remove-Item $FileName

#Формируем имя временного каталога RedMine
Write-Host "Create: $FileName"

#Создать временный каталог для архива
"ssh root@ 'mkdir "+$BackUpPath+"'">>$FileName

#Архив файлов
"ssh root@ 'tar -cvf "+$BackUpPath+"/files.tar.gz /var/www/redmine/files'">>$FileName

#Архив Git
"ssh root@ 'tar -cvf "+$BackUpPath+"/git.tar.gz /srv/repos/git'">>$FileName

#Архив базы RedMine
"ssh root@ '/usr/bin/mysqldump -u redmine -p9323XXXXXXX13ad redmine_production | gzip > "+$BackUpPath+"/redmineDB.gz'">>$FileName

#Запуск скрипта архивации
Write-Host "Run: $FileName"

#Копировние временного каталога RedMine в текущий рабочий каталог Windows
Write-Host "Copy dir from $BackUpPath to "(Get-Location)
scp -r root@$BackUpPath (Get-Location)

#Создаем (удаляя предыдущий) скрипт удаления временного каталога RedMine
$FileName = "DelBackUpScript.ps1"
if (Test-Path $FileName) 
  Remove-Item $FileName
#Запуск скрипта удаления
"ssh root@ 'rm -r "+ $BackUpPath+"'">>$FileName
Write-Host "Run: $FileName"

The data for the line of the RedMine database archive should be taken from /var/www/redmine/config/database.yml

6. Windows. Launch PowerShell, go to the directory with StartBackUp.ps1 and launch it for execution.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *