-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-system-config.rsc
52 lines (49 loc) · 1.35 KB
/
backup-system-config.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# backup system config
:local isFound;
:local value;
:local version;
:local architecture;
:local path "{path-for-backup-folder}";
:local isNeedPackage true;
:log info "backup system config";
# add device name to path
/system identity;
:set value [get name];
:set path "$path/$value";
# back startup config
/;
export file="$path/startup.rsc" show-sensitive;
# back system settings
/system backup;
save dont-encrypt=yes name="$path/system.backup";
# back user manager database
/system package;
:foreach package in=[find where name=user-manager] do={
/user-manager database;
save name="$path/user-manager.umb" overwrite=yes;
};
# get system information
/system resource;
:set architecture [get architecture-name];
:set value [get version];
:set value [:pick $value 0 [:find $value " "]];
:set version $value;
# work with package file
:if ($isNeedPackage) do={
# delete old package file
/file;
:set isFound false;
:foreach file in=[find where name~"$path/" type="package"] do={
:set value [get $file package-architecture];
:if ([:pick $architecture 0 [:len $value]] = $value && [get $file package-version] = $version) do={
:set isFound true;
} else={
remove [get $file name];
};
};
# download new package file
/tool;
:if (!$isFound) do={
fetch url="https://download.mikrotik.com/routeros/$version/routeros-$version-$architecture.npk" dst-path "$path";
};
};