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
Conversation
This script will backup the userdata (except unnecessary files) and conf folders into a .zip file. Signed-off-by: Brian Leedy <awsnap@gmail.com>
Signed-off-by: Brian Leedy <awsnap@gmail.com>
Signed-off-by: Brian Leedy <awsnap@gmail.com>
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? |
@BClark09 it tells you in the well documented
If you are on
|
Thank you @DarkLite1, unfortunately I could not get it to work. The backup folder is set as |
I remember that occurring but I thought I had fixed it. I’ll try to take a look in the next day or two. Thanks for trying it.
On Sep 23, 2017, at 4:08 PM, Ben Clark <notifications@github.com> wrote:
Thank you @DarkLite1, unfortunately I could not get it to work.
The backup folder is set as ./backups, however it looks like the error references the backup folder to be in system32!?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
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 |
@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? |
Yes actually. I’ll have time Tuesday.
(Sent from my iPhone)
On Dec 10, 2017, at 3:17 PM, Kai Kreuzer <notifications@github.com> wrote:
@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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@bdleedy |
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. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting this to something like "windows" would be better for cross platform compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the 'this' you are referring to? The directory, property, file, ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines (82 and 83) have to be moved before L76 and L77 for the script to work properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and ready to go, just waiting on your clarification above.
Sorry, no time for the moment. Packing to leave on a vacation trip tomorrow.. |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thats working well! Thanks @bdleedy!
Hooray thanks guys! |
Awesome! |
@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. |
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