I have recently been deployed to manage a mikrotik core router with a usermanager database that's been wiped. I have a list of the names, department, matriculation number and more of users. I wish to have a way to upload this to the usermanager instead of going the manual route. Router OS is 6.49.19. I'd be glad to have some help. Please note that i am new to mikrotik so i'd appreciate making it as simple as possible
It depends on the exact version of user manager, cannot say which fields any specific version may support or not support.
The general principle is to make a .rsc file (a plain .txt file with changed extension) and then import it on the router.
Depending on the number of entries it may be wise to divide it in several files, and this may also depend on how much storage space you have available and how much powerful is the device as importing is likely to make CPU spikes.
BUT if you make an export with the flag "terse", each line will be "self-standing", i.e.:
export will be something like :
/tool user-manager user add username=vultur.ionutdacian password="1" phone="01V010" last-name="VULTUR" first-name="IONUT-DACIAN" location=201-A
/tool user-manager user add username=bubulica.mariasimona password="by8ahe5e7" phone="02B021" last-name="BUBULICA" first-name="MARIA-SIMONA" location=
/tool user-manager user add username=ciobotea.dorin password="ebute7yty" phone="02C030" last-name="CIOBOTEA" first-name="DORIN" location=
/tool user-manager user add username=cojocaru.iosifcostel password="avaju8u3y" phone="02C031" last-name="COJOCARU" first-name="IOSIF-COSTEL" location=
/tool user-manager user add username=gheorghe.elenalavinia password="1" phone="02G005" last-name="GHEORGHE" first-name="ELENA-LAVINIA" location=
/tool user-manager user add username=marinica.ramonamariana password="1" phone="02M025" last-name="MARINICA" first-name="RAMONA-MARIANA" location=
This latter form can be divided arbitrarily in as many files as you wish, as each line in itself is a command.
A small batch like this will create the files (windows):
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
::divideetimpera.cmd small batch file to divide text files into multiple files with a given number of lines
::usage diviteetimpera.cmd <filename> <max_number_of:lines
::example: divideetimpera.cmd testdata.rsc 1000
::D:\Mikrotik\User_manager>divideetimpera.cmd testdata.rsc 1000
::D:\Mikrotik\User_manager\testdata.rsc
::Writing file D:\Mikrotik\User_manager\testdata_001.rsc with 1000 entries
::Writing file D:\Mikrotik\User_manager\testdata_002.rsc with 1000 entries
::Writing file D:\Mikrotik\User_manager\testdata_003.rsc with 1000 entries
::Writing file D:\Mikrotik\User_manager\testdata_004.rsc with 1000 entries
::Writing file D:\Mikrotik\User_manager\testdata_005.rsc with 783 entries
SET targetfile=%~dpn1
SET targetext=%~x1
SET maxlines=%2
IF NOT DEFINED maxlines SET maxlines=500
SET /A linecounter=0
SET filecounter=0
DEL %~dpn1_*%~x1
CALL :nextfile
ECHO %target%
FOR /F "tokens=1 delims=" %%A IN ( %target% ) DO (
SET /A linecounter+=1
ECHO %%A>>%targetfile%_!filesuffix!%targetext%
IF !linecounter!==%maxlines% CALL :nextfile
)
ECHO Writing file %targetfile%_!filesuffix!%targetext% with %linecounter% entries
GOTO :EOF
:nextfile
IF %linecounter%==%maxlines% ECHO Writing file %targetfile%_!filesuffix!%targetext% with %linecounter% entries
SET /A filecounter+=1
SET filesuffix=00%filecounter%
SET filesuffix=%filesuffix:~-3,3%
SET /A linecounter=0
GOTO :EOF