Community discussions

MikroTik App
 
cybergold
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu May 25, 2006 3:36 am

script to backup usermanager data everyday

Sun Apr 01, 2007 5:54 pm

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.
 
User avatar
skillful
Trainer
Trainer
Posts: 552
Joined: Wed Sep 06, 2006 1:42 pm
Location: Abuja, Nigeria
Contact:

Sun Apr 01, 2007 10:40 pm

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
 
cybergold
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu May 25, 2006 3:36 am

Mon Apr 02, 2007 9:20 am

this did not work for me... message got is ''no such command as add'' Can anyone else assist pls?
 
cmit
Forum Guru
Forum Guru
Posts: 1547
Joined: Fri May 28, 2004 12:49 pm
Location: Germany

Mon Apr 02, 2007 9:24 am

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
 
cybergold
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu May 25, 2006 3:36 am

Mon Apr 02, 2007 11:03 am

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
 
cmit
Forum Guru
Forum Guru
Posts: 1547
Joined: Fri May 28, 2004 12:49 pm
Location: Germany

Mon Apr 02, 2007 11:39 am

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
 
cybergold
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 50
Joined: Thu May 25, 2006 3:36 am

Mon Apr 02, 2007 12:16 pm

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
 
cmit
Forum Guru
Forum Guru
Posts: 1547
Joined: Fri May 28, 2004 12:49 pm
Location: Germany

Mon Apr 02, 2007 12:36 pm

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
 
shawnsmith
just joined
Posts: 12
Joined: Thu Jun 07, 2007 5:54 pm

Re: script to backup usermanager data everyday

Mon Aug 27, 2007 2:36 pm

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.
 
JJCinAZ
Member
Member
Posts: 475
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ

Re: script to backup usermanager data everyday

Wed Sep 05, 2007 7:20 pm

I can replicate this, but I can't find a way to make this work. Did you get any resolution?
 
shawnsmith
just joined
Posts: 12
Joined: Thu Jun 07, 2007 5:54 pm

Re: script to backup usermanager data everyday

Thu Sep 06, 2007 4:51 pm

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 ?
 
JJCinAZ
Member
Member
Posts: 475
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ

Re: script to backup usermanager data everyday

Thu Sep 06, 2007 6:07 pm

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.
 
JJCinAZ
Member
Member
Posts: 475
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ

Re: script to backup usermanager data everyday

Fri Sep 07, 2007 9:24 pm

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.
 
shawnsmith
just joined
Posts: 12
Joined: Thu Jun 07, 2007 5:54 pm

Re: script to backup usermanager data everyday

Fri Sep 14, 2007 10:18 am

If you are using the /tool user-manager export feature to backup your DB, how do you restore the exported data ?

Shawn
 
JJCinAZ
Member
Member
Posts: 475
Joined: Fri Oct 22, 2004 8:03 am
Location: Tucson, AZ

Re: script to backup usermanager data everyday

Fri Sep 14, 2007 8:04 pm

Very carefully. It's a manual and tedious process. Instead, I just moved my User Manager to an Intel box.
 
User avatar
Giepie
Member
Member
Posts: 433
Joined: Mon Sep 13, 2004 12:33 pm
Location: Western Cape, South Africa
Contact:

Re: script to backup usermanager data everyday

Sat Jun 21, 2008 2:29 am

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
 
Premier
Member Candidate
Member Candidate
Posts: 129
Joined: Mon Jul 19, 2010 8:52 pm

Re: script to backup usermanager data everyday

Sun Nov 14, 2010 2:42 pm

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?
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: script to backup usermanager data everyday

Sun Nov 14, 2010 10:15 pm

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,
 
User avatar
bax
Member Candidate
Member Candidate
Posts: 268
Joined: Mon Dec 20, 2004 8:45 pm
Location: Croatia

Re: script to backup usermanager data everyday

Sat Nov 27, 2010 10:00 pm

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 :)
 
H2009
Member Candidate
Member Candidate
Posts: 137
Joined: Tue Oct 26, 2010 8:46 am

Re: script to backup usermanager data everyday

Mon Dec 06, 2010 8:49 pm

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

 
User avatar
bax
Member Candidate
Member Candidate
Posts: 268
Joined: Mon Dec 20, 2004 8:45 pm
Location: Croatia

Re: script to backup usermanager data everyday

Mon Dec 06, 2010 9:36 pm

easier is to disconnect all active users ...
 
stenlycicero
just joined
Posts: 3
Joined: Tue Dec 18, 2012 1:46 pm

Re: script to backup usermanager data everyday

Tue Dec 18, 2012 1:54 pm

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. :(
 
User avatar
Giepie
Member
Member
Posts: 433
Joined: Mon Sep 13, 2004 12:33 pm
Location: Western Cape, South Africa
Contact:

Re: script to backup usermanager data everyday

Wed Dec 19, 2012 6:38 pm

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
 
stenlycicero
just joined
Posts: 3
Joined: Tue Dec 18, 2012 1:46 pm

Re: script to backup usermanager data everyday

Thu Dec 20, 2012 3:44 am

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.

Who is online

Users browsing this forum: No registered users and 7 guests