Auto backup

Got a good idea? You can suggest new features here.
Post Reply
Experienced User
Posts: 55
Joined: Fri Jul 07, 2017 9:59 pm

Auto backup

Post by scottsams » Fri Aug 11, 2017 10:35 pm

As I am building out my panel, my config is growing. I have two instances (2 PCS) doing different things. This is great! It'd be cool to have an auto config backup. I am sure I can do it within EG but just thought it would be a good idea. One that could backup based on time and keep # iterations.


User avatar
Site Admin
Posts: 3407
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Auto backup

Post by kgschlosser » Sat Aug 12, 2017 12:19 am

shoot there is a file plugin that will allow you to monitor for changes to the file and from this you can do a backup. you can also use robocopy (included with windows) which can perform the same task.
If you like the work I have been doing then feel free to Image

User avatar
Experienced User
Posts: 90
Joined: Tue Aug 20, 2013 7:14 pm
Location: Moscow, Russia

Re: Auto backup

Post by Neytrino-OnLine » Fri Oct 27, 2017 2:20 pm

I make something for myself, maybe it will be helpful for others...
What I wanted: when I do something in my EG profile, usually I don't think of backup copies (don't know why) and just make some changes in my current profile. So when it is done, I completely lose the previous version of a profile (as fact: I only have two early profile versions, which have been kept during reinstallation of Windows)... So I needed function that will check the my profile file from time to time, and copies it in the folder (named with the current date and time) if it has changes, and I have make it:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
    <Folder Name="Profile BackUp" XML_Guid="{ED943057-A777-49E6-85B0-09F899813C4C}">
        <Macro Name="Should be executed on EG start..." XML_Guid="{2A2375C2-B40D-4CF8-BF2D-D57C8B1752AC}">
            <Event Name="Main.OnInit" XML_Guid="{73ED945E-0EC0-4F46-A7D3-3BB5006796EF}" />
            <Action XML_Guid="{0A9E6E25-3016-4FAB-97DC-874C2617C0B4}">
                EventGhost.PythonScript(u'def ProfileBackUp(profile_folder, profile_name, backup_folder, eg_version):\n    import os, shutil, datetime\n\n    if eg_version == 4:\n        extension = \'.xml)\'\n    elif eg_version == 5:\n        extension = \'.egtree\'\n    profile_path = profile_folder + profile_name + extension\n    if os.path.exists(profile_path) and os.path.isfile(profile_path):\n        if os.path.exists(backup_folder) and os.path.isdir(backup_folder):\n            listdir = os.listdir(backup_folder)\n            if len(listdir):\n                backup_path = backup_folder + listdir[len(listdir) - 1] + \'\\\\\' + profile_name + extension\n                if os.path.exists(backup_path) and os.path.isfile(backup_path):\n                    if os.path.getmtime(profile_path) &lt; os.path.getmtime(backup_path):\n                        print \'BackUp: no needed...\'\n                        return False\n        dt =\n        date_and_time = str(dt[0]) + \'.\' + str(dt[1]).zfill(2) + \'.\' + str(dt[2]).zfill(2) + \' - \' + str(dt[3]).zfill(2) + \'.\' + str(dt[4]).zfill(2) + \'\\\\\'\n        os.makedirs(backup_folder + date_and_time, mode=0o777)\n        shutil.copy(profile_path, backup_folder + date_and_time)\n        print \'BackUp: executed...\'\n        return True\n    else:\n        eg.PrintError(\'File; "\' + profile_name + extension + \'" is not found in: "\' + profile_folder + \'"...\')\n        return False\n\neg.globals.ProfileBackUp = ProfileBackUp')
            <Action XML_Guid="{0045C9DE-39A8-4C55-B65C-65582414BDD4}">
                EventGhost.TriggerEvent(u'BackUp', 0.0)
        <Macro Name="BackUp" XML_Guid="{CA1A4AEE-18A6-438E-AB0D-D7A4BE984363}">
            <Event Name="Main.BackUp" XML_Guid="{40B858ED-0FAB-4243-BCB3-019089A1CC37}" />
            <Action XML_Guid="{B19876D4-5DF2-4AA4-A089-DBF81376A484}">
                EventGhost.PythonCommand(u"eg.globals.ProfileBackUp('C:\\\\Profile\\\\', 'Profile', 'C:\\\\Profile\\\\BackUp\\\\', 5)")
            <Action XML_Guid="{0045C9DE-39A8-4C55-B65C-65582414BDD4}">
                EventGhost.TriggerEvent(u'BackUp', 3600.0)
Function has four arguments:
1 - profile folder (don't forget use double "\")
2 - profile name (only name, without extensions)
3 - backup folder
4 - EG version (4 - will work with *.xml files, 5 with *.egtree)
Every time when you execute function, it checks: date of last profile change and if the profile has been changed after last backup, it has been make one more backup, if it isn't present - function will do nothing...
Sin©erely yours, Neytrino.

Post Reply