Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup script for Windows #512

Merged
merged 4 commits into from Dec 14, 2017

Conversation

Projects
None yet
6 participants
@bdleedy
Copy link
Contributor

commented Aug 7, 2017

This script will backup the userdata (except unnecessary files) and conf
folders into a .zip file.

For #499

Signed-off-by: Brian Leedy awsnap@gmail.com

bdleedy added some commits Aug 7, 2017

Add backup.ps1 script for Windows
This script will backup the userdata (except unnecessary files) and conf
folders into a .zip file.

Signed-off-by: Brian Leedy <awsnap@gmail.com>
Fixed help
Signed-off-by: Brian Leedy <awsnap@gmail.com>
Fixed backups directory location
Signed-off-by: Brian Leedy <awsnap@gmail.com>
@BClark09

This comment has been minimized.

Copy link
Member

commented Sep 20, 2017

Hi @bdleedy, I'm a PowerScript novice. But wanted to test out the script today to see if it produces the same zip as the Linux version, how do I use the file? Running it by right-click doesn't seem to do anything?

@DarkLite1

This comment has been minimized.

Copy link

commented Sep 23, 2017

@BClark09 it tells you in the well documented .EXAMPLE section how to use it:

+    .EXAMPLE
 +    Backup an openHAB instance to a zip file
 +    Backup-openHAB
 +    .EXAMPLE
 +    Backup the openHAB distribution in the C:\openHAB2 directory to c:\openhab-backup\backup.zip
 +    Backup-openHAB -OHDirectory C:\openHAB2 -OHBackups c:\openHAB-backup -ZipFileOut backup.zip

If you are on Windows box it should be possible to load the function first and then you can use it as in the example. Something like this would do:

# Loads the function
& 'C:\Backup.ps1'

# Executes the function
Backup-openHAB
@BClark09

This comment has been minimized.

Copy link
Member

commented Sep 23, 2017

Thank you @DarkLite1, unfortunately I could not get it to work.

image

The backup folder is set as .\backups, however it looks like the error references the backup folder to be in system32!? I'm assuming these directories should probably be expanded to a full path first.

@bdleedy

This comment has been minimized.

Copy link
Contributor Author

commented Sep 23, 2017

@DarkLite1

This comment has been minimized.

Copy link

commented Sep 24, 2017

You probably already know this, but I feel I need to say it anyhow. To have this work on all Windows machines you need to use PowerShell.exe -ExecutionPolicy Bypass -Command {MyCode}.

@kaikreuzer

This comment has been minimized.

Copy link
Member

commented Dec 10, 2017

@bdleedy Are you still around? As we are heading towards the 2.2 by the end of this week, is there any chance to finish this off?

@bdleedy

This comment has been minimized.

Copy link
Contributor Author

commented Dec 10, 2017

@tmrobert8

This comment has been minimized.

Copy link
Contributor

commented Dec 12, 2017

@bdleedy
Let me know if you want any help on testing it (or the update.ps1) - I can certainly take the time to test.

@bdleedy bdleedy force-pushed the bdleedy:backup-ps1 branch from ca99887 to d25870e Dec 13, 2017

@bdleedy

This comment has been minimized.

Copy link
Contributor Author

commented Dec 13, 2017

Seems like the CreateFromDirectory doesn't like .\ so I handled that and used pwd to grab the current directory.

@tmrobert8 et al, this needs a quick test also.

@bdleedy bdleedy force-pushed the bdleedy:backup-ps1 branch from d25870e to 98f285c Dec 13, 2017

@DarkLite1

This comment has been minimized.

Copy link

commented Dec 13, 2017

When we create production code in PowerShell we usually create a Pester file full of tests. It could maybe be an idea to add this too. Makes updating easier in the future.

@BClark09
Copy link
Member

left a comment

I can't comment on efficiency/safety of the code. (@DarkLite1 are you able to comment?) but I can say that it fails to include backup.properties to the zipfile. Implementing my comments seems to resolve the issue and a good zip file is created.

$CurrentVersionIndex = $VersionLine.IndexOf(":")
$CurrentVersion = $VersionLine.Substring($currentVersionIndex + 2)
$timestamp = Get-Date -Format yyyyMMddHHmm
Write-Output "version=$CurrentVersion" | Set-Content "$TempDir\backup.properties"

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

$TempDir hasn't been set yet, so this writes backup.properties to the C:\\ root.

$timestamp = Get-Date -Format yyyyMMddHHmm
Write-Output "version=$CurrentVersion" | Set-Content "$TempDir\backup.properties"
Write-Output "timestamp=$timestamp" | Add-Content "$TempDir\backup.properties"
#Write-Output "user=$OHUser" | Add-Content "$TempDir\backup.properties"

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

Setting this to something like "windows" would be better for cross platform compatibility.

This comment has been minimized.

Copy link
@bdleedy

bdleedy Dec 13, 2017

Author Contributor

What is the 'this' you are referring to? The directory, property, file, ...?

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

Apologies, I assume you commented out this line because OHUser and OHGroup is blank? If you set to this to the default: user=openhab, group=openhab then it would be clearer to the restore scripts on other operating systems.

This comment has been minimized.

Copy link
@bdleedy

bdleedy Dec 13, 2017

Author Contributor

Yeah, in Windows there isn't a real reason to grab that info as there is in your case so I just left if commented out in case someone thought we needed something there. I'll just hardcode 'openhab' for both then. Check that. openHAB.

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

Case is important in unix/macos, so please let it be 'openhab'. The idea here is to be able to use a backup from Windows, on a restore to Unix, and visa versa.

Write-Output "version=$CurrentVersion" | Set-Content "$TempDir\backup.properties"
Write-Output "timestamp=$timestamp" | Add-Content "$TempDir\backup.properties"
#Write-Output "user=$OHUser" | Add-Content "$TempDir\backup.properties"
#Write-Output "group=$OHGroup" | Add-Content "$TempDir\backup.properties"

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

Same as above.

#Write-Output "group=$OHGroup" | Add-Content "$TempDir\backup.properties"

Write-Host -ForegroundColor Cyan "Copying userdata and conf folder contents to temp directory"
$TempDir=([Environment]::GetEnvironmentVariable("TEMP", "Machine"))+"\openhab"

This comment has been minimized.

Copy link
@BClark09

BClark09 Dec 13, 2017

Member

These two lines (82 and 83) have to be moved before L76 and L77 for the script to work properly.

This comment has been minimized.

Copy link
@bdleedy

bdleedy Dec 13, 2017

Author Contributor

Fixed and ready to go, just waiting on your clarification above.

@bdleedy bdleedy force-pushed the bdleedy:backup-ps1 branch from 98f285c to 342bc9d Dec 13, 2017

@DarkLite1

This comment has been minimized.

Copy link

commented Dec 13, 2017

Sorry, no time for the moment. Packing to leave on a vacation trip tomorrow..

Fix backup.properties
Fixed issue with CreateFromDirectory using .\ relative path
Fixed synopsis
Moved $TempDir creation up, added default user and group of openHAB to
backup.properties
Changed openHAB to openhab in backup.properties

Signed-off-by: Brian Leedy <awsnap@gmail.com>

@bdleedy bdleedy force-pushed the bdleedy:backup-ps1 branch from 342bc9d to a932621 Dec 14, 2017

@tmrobert8

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2017

@bdleedy
This worked fine for me - great job! Are you going to wrap both of these in an easily executed .bat file (I have .bat wrappers around both right now - pretty simple to create).

@BClark09
Copy link
Member

left a comment

Excellent, thats working well! Thanks @bdleedy!

@martinvw

This comment has been minimized.

Copy link
Member

commented Dec 14, 2017

Hooray thanks guys!

@kaikreuzer

This comment has been minimized.

Copy link
Member

commented Dec 14, 2017

Awesome!

@kaikreuzer kaikreuzer merged commit 70392f4 into openhab:master Dec 14, 2017

1 check passed

Jenkins This pull request looks good
Details
@bdleedy

This comment has been minimized.

Copy link
Contributor Author

commented Dec 14, 2017

@tmrobert8 I kind of despise .bat wrappers a little but I think it makes sense in this case and easier for 'Joe Automator' to use. I can do a PR or feel free to do it yourself. I need to work on the update script still and I'm making progress on the restore script but behind on that. Also, the documentation needs some work as well.

@kaikreuzer kaikreuzer changed the title Add backup.ps1 script for Windows Added backup script for Windows Dec 15, 2017

@kaikreuzer kaikreuzer added this to the 2.2 milestone Dec 15, 2017

@kaikreuzer kaikreuzer changed the title Added backup script for Windows Backup script for Windows Dec 15, 2017

@kaikreuzer kaikreuzer modified the milestone: 2.2 Dec 15, 2017

@bdleedy bdleedy deleted the bdleedy:backup-ps1 branch Dec 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.