Page 1 of 1

script to backup usermanager data everyday

Posted: Sun Apr 01, 2007 5:54 pm
by cybergold
hello all,
Top of the day to you all. How do i write a script to back up usermanager data everyday at 3pm? I have to do a manual back up of usermanager data each time using the terminal mode...[admin@MT] tool user-manager database..
Urgent help needed pls.

Posted: Sun Apr 01, 2007 10:40 pm
by skillful
copy and paste this command in a terminal window:

add name="backup_userman_database" on-event="/tool user-man database save name=userman" \
start-date=jan/01/1970 start-time=15:00:00 interval=1d comment="" \
disabled=no

Posted: Mon Apr 02, 2007 9:20 am
by cybergold
this did not work for me... message got is ''no such command as add'' Can anyone else assist pls?

Posted: Mon Apr 02, 2007 9:24 am
by cmit
cybergold, add a "/system scheduler" in front of the command you have been given in the post above, then it should work.

Best regards,
Christian Meis

Posted: Mon Apr 02, 2007 11:03 am
by cybergold
Chris, thanks for the response... can you still be a lot more helpful if you just write out the command line out in full for me. I built my MT from scratch by myself and i hate to get things complicated now. thanks

Posted: Mon Apr 02, 2007 11:39 am
by cmit
Copy and paste this:
/system scheduler add name="backup_userman_database" on-event="/tool user-manager database save name=userman" \ 
start-date=jan/01/1970 start-time=15:00:00 interval=1d comment="" \ 
disabled=no
This should save your user-manager database everyday at 15:00 to a file named "userman.umb". You could restore this database using the "/tool user-manager database load name=userman" command.

Explanation: The originally posted command (starting directly with "add ..." will only work if you are at the "/system scheduler" hierarchy of the console, i.e. your console prompt does already show " system scheduler>"...

Best regards,
Christian Meis

Posted: Mon Apr 02, 2007 12:16 pm
by cybergold
Cool Chris, i now have an automated backup mechanism.. kindly let me know which other activities i can automate like this.

Am not good at all at scripting, but would like to learn

Posted: Mon Apr 02, 2007 12:36 pm
by cmit
You can automate lots of things. As you can use practically every RouterOS command in scripts, the possibilities are endless...

Perhaps look around here in the scripting forum and the wiki, there are lots of examples for using the scripting facilities.

Best regards,
Christian Meis

Re: script to backup usermanager data everyday

Posted: Mon Aug 27, 2007 2:36 pm
by shawnsmith
I have been backing up the userman db with this script now, but when i try to restore, it gives me the following error.:

> tool user-manager database load name=userman.umb
Restore user-manager database? [y/N]: y
Loading user-manager database backup
Failed to load user-manager database backup
broken file

Any ideas ? i have tried this on a different RB and it gives me the same error ??

my script looks like this :

/tool user-manager database save name=userman

Any help would be appreciated.

Re: script to backup usermanager data everyday

Posted: Wed Sep 05, 2007 7:20 pm
by JJCinAZ
I can replicate this, but I can't find a way to make this work. Did you get any resolution?

Re: script to backup usermanager data everyday

Posted: Thu Sep 06, 2007 4:51 pm
by shawnsmith
No, i still have this problem. I have no idea as to what is causing it or how to resolve it.
How did you replicate the error ?

Re: script to backup usermanager data everyday

Posted: Thu Sep 06, 2007 6:07 pm
by JJCinAZ
Replication was on a 2.9.46 RB5XX build. Just did a /tool user-manager database save name=file then a corresponding load. I haven't tried this on an x86 build or on 3.0rc4. Currently, I'm using an export to get a backup.

Re: script to backup usermanager data everyday

Posted: Fri Sep 07, 2007 9:24 pm
by JJCinAZ
Just tested the backup and restore (save/load) of the user manager database on an Intel based router and it worked fine. This suggests an endian problem with the code because this only fails for me on MIPS based routers.

Re: script to backup usermanager data everyday

Posted: Fri Sep 14, 2007 10:18 am
by shawnsmith
If you are using the /tool user-manager export feature to backup your DB, how do you restore the exported data ?

Shawn

Re: script to backup usermanager data everyday

Posted: Fri Sep 14, 2007 8:04 pm
by JJCinAZ
Very carefully. It's a manual and tedious process. Instead, I just moved my User Manager to an Intel box.

Re: script to backup usermanager data everyday

Posted: Sat Jun 21, 2008 2:29 am
by Giepie
Hi Shawn

What version of MT are you running on the UM you wish to backup?

If my mind serves me right, the very first versions of UM could not be restored to the later versions, so you first had to upgrade your UM system and then do a backup.

I hope this is helpful.

G

Re: script to backup usermanager data everyday

Posted: Sun Nov 14, 2010 2:42 pm
by Premier
Sorry for bringing up an almost 2 year old thread but I feel this is relevant to the subject......
Is there a way to have an external server independant to the Usermanager back up the database remotely instead of having it just on the UserManager just incase the Usermanager's data is lost due to a fault?

Re: script to backup usermanager data everyday

Posted: Sun Nov 14, 2010 10:15 pm
by dssmiktik
Sorry for bringing up an almost 2 year old thread but I feel this is relevant to the subject......
Is there a way to have an external server independant to the Usermanager back up the database remotely instead of having it just on the UserManager just incase the Usermanager's data is lost due to a fault?
Yes, you could backup the usermanager's database, then use external tools like scp or ftp to pull the file off the router and onto the target. SSH or API could be used to trigger the backup remotely and run the necessary command on the router itself.

Hope this helps,

Re: script to backup usermanager data everyday

Posted: Sat Nov 27, 2010 10:00 pm
by bax
I have been backing up the userman db with this script now, but when i try to restore, it gives me the following error.:

> tool user-manager database load name=userman.umb
Restore user-manager database? [y/N]: y
Loading user-manager database backup
Failed to load user-manager database backup
broken file

Any ideas ? i have tried this on a different RB and it gives me the same error ??

my script looks like this :

/tool user-manager database save name=userman

Any help would be appreciated.
This is hapening because you have active hotspot or ppp users ... you must do backup when is no active users ... or disconect all active users :)

Re: script to backup usermanager data everyday

Posted: Mon Dec 06, 2010 8:49 pm
by H2009
Following on from this script here below, would it be possible to introduce a check to see if any users are active, and if so, wait 5 minutes (loop).

/system scheduler add name="backup_userman_database" on-event="/tool user-manager database save name=userman" \ 
start-date=jan/01/1970 start-time=15:00:00 interval=1d comment="" \ 
disabled=no


Re: script to backup usermanager data everyday

Posted: Mon Dec 06, 2010 9:36 pm
by bax
easier is to disconnect all active users ...

Re: script to backup usermanager data everyday

Posted: Tue Dec 18, 2012 1:54 pm
by stenlycicero
sorry for bringin up this old thread.
is there anyway to recover "broken file" of User manager umb database ?

i've experience this problem after incidentally backup with several of users in active mode.
and the router is just being netinstalled. :(

Re: script to backup usermanager data everyday

Posted: Wed Dec 19, 2012 6:38 pm
by Giepie
You should be able to rebuild the DB with this command:

/tool user-manager database rebuild

I've had to done it a few times. It is not always sucessful though.

Hope it helps :)

G

Re: script to backup usermanager data everyday

Posted: Thu Dec 20, 2012 3:44 am
by stenlycicero
i've done the rebuild and it's successful restore the old one backup file.
when i trying to restore the latest backup file, it's still comes with the same error: broken file.

as long as i remember, when the "save" process executed, there are several user in active mode.