Snippets Project Page
Author: maroon
Added: 5y
Updated: 5y
mIRC: used 6.35 & 7.52+
Hits: 2,027
Downloads: 42
Review: entropy
Size: 10.37KB
1 0
Login to vote.
mirc.ini Backup
v1.1
Defend against your mIRC configuration settings being trashed because windows crashes while writing to mirc.ini
Saves mirc.ini to a backup named after the day of the week, at 2 hours intervals.
If your mirc.ini does get reset to defaults, you can quit mirc.exe then copy one of the backups on top of the mirc.ini being used.
Download
JSON
▲ Review
▲ Log
▼ Source
/* { mIRCiniBackup v1.1 by maroon. Saves backup of mirc.ini at 2 hours intervals! Syntax: /mIRCiniBackup [now] [duration string | hours ] If you wish to accept the default 2 hours, there's nothing to do except install this script, then wait for mirc.ini to get trashed. Otherwise: /mIRCiniBackup now ... forces script to backup mirc.ini now, even if it's not yet time. /mIRCiniBackup 90 min /mIRCiniBackup 1.5 hr /mIRCiniBackup 1 hr 30 min /mIRCiniBackup 3 ... any string accepted as a parameter in $duration(string) overrides the default 2 hour interval, except any number-only is hours, and it only accepts intervals as large as 24 hours. This resets the timer to be that distance into the future, but doesn't trigger a backup unless the backup is changed to an interval already past due according to the time of the most recent backup. To also force the backup now, insert the 'now' parameter: /mIRCiniBackup now 90 min If mirc.ini is damaged, it gets reset to default, and no longer contains a list of loaded scripts, which means this script won't be loaded where it could backup a damaged mirc.ini on top of a 'good' one. You can restore settings and scripts by: 1. Quit mirc.exe 2. Copy one of the 7 daily backup files on top of the mirc.ini being used by mIRC. These backups are in same folder where mirc.ini is. 3. Just to be safe, copy these 7 files somewhere safe, until you've fixed your problem. 4. restart mirc.exe to see if you chose the best backup. The reason to copy your 7 daily backups somewhere safe is that if you restore a backup mirc.ini that contains this script file as one of the loaded scripts, it will immediately copy that mirc.ini on top of the backup named after today's date, which you may not want to happen. The backups will have a timestamp from when the backup was made, not when the last configuration change was made. Even though mIRC has taken steps to avoid the problem, I've continued to see reports of people losing their settings in a crash. mirc.ini can become damaged if Windows crashes while mIRC is shutting down, or at other times when mIRC is busy writing to mirc.ini. When that happens, mirc.ini can become a zero byte file, so mIRC replaces mirc.ini with a default copy, and all your configuration changes are gone. The chances of your scripts also being lost is very low since mIRC isn't writing to script files very often. One of the effects of mirc.ini being reset to default is that your mirc.ini no longer contains a list of loaded scripts. However your scripts are almost certainly where they belong and undamaged. If you can quit mIRC then copy a recent backup of mirc.ini to the path\filename where mirc.exe is looking for mirc.ini, you should be fine, except for not having changed settings made within the recent few hours after the last backup. By saving backups to 7 different files, this script eliminates the chance that mIRC crashes during the backup and ruins the only backup and the original at the same time. It also gives you the chance to restore settings to the way they were in previous days, or you can edit the script to make monthly backups too. The semicolon'ed lines show how to backup other files if you wish to backup them too. The other files usually don't get trashed during a crash the way mirc.ini can, so I didn't enable backup of those files too. In addition to saving backups named after the days of the week, you can remove a semi-colon to activate a line which saves a backup of mirc.ini to the name of the current month, which helps for configuration changes that you may not be aware of for longer periods of time, such as minor changes to your color settings. This would eventually cause the backup to display copying 12+7=19 files, so you can change "copy" to ".copy" to suppress the display - or you can delete very old monthly backups. Even though the default interval is 2 hrs, the script often displays a message that the next backup will execute 1 second shorter than the interval. That's because of the way $timer().secs reports. //timertest 1 10 noop | echo -a $timer(test).secs ... usually reports 9 instead of 10. mIRC takes the number of milliseconds, then divides by 1000 and drops the fraction. Changelog: v1.1 added control.ini as an optional file to be backedup. } */ ; if you wish the interval to be a different number of hours instead of 2 hours, edit the '2' in the START event. ; It takes effect next time you start mIRC, or you can paste the new command in the editbox like: /mIRCiniBackup 3 hours ON *:START:{ mIRCiniBackup 2 hours } alias mIRCiniBackup { var %mIRCiniBackup.interval 3600 * 2 var %now 0 , %new.interval %mIRCiniBackup.interval , %delay $timer(mIRCiniBackup).delay , %sc $chr(3) $+ 0, $+ $color(notice) if (($timer(mIRCiniBackup)) && (%delay)) var %mIRCiniBackup.interval %delay if ($1 == now) { inc %now | tokenize 32 $2- } if ($duration($1-) isnum 1-86400) var %new.interval $v1 elseif ($1 isnum 0-24) var %new.interval $1 * 3600 elseif ((%delay) && (%delay != %new.interval)) var %new.interval %delay if (($ctimer) && ($ctimer != mIRCiniBackup) && ($timer(mIRCiniBackup))) { echo -sgc info * mIRCiniBackup: won't run from duplicate timer $ctimer | return } echo -sg %sc =/=/=/=/=/=/= mIRCiniBackup by maroon $+ $chr(169) v1.1 backs up mirc.ini at $duration(%mIRCiniBackup.interval) intervals! $chr(3) if ((($script(0)) && ($calc($ctime +1- %mIRCiniBackup.NewestBackup) >= %mIRCiniBackup.interval)) || (%now)) { ; saveini forces pending changes to be written to disk, to avoid being lost in a crash saveini echo -sg $+($chr(3),8,$chr(44),12) Backups being done NOW! $chr(3) var %dow $calc($calc(1+($int($calc(($ctime($date 12:00) - $ctime(4/1/1970 00:00)) /86400)) % 7))) , %weekday $asctime($ctime,dddd) , %month $asctime($ctime,mm_mmmm) var %file $mircini | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; removing semi-colon from the lines in the next group which begin with "; var" activates those commands instead of being comments ; To suppress the display of the COPY commands in this script, change copy to .copy ; make 12 extra monthly backups of mirc.ini named after the months. ; var %file $mircini | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%month,.bak)) ; next lines show examples of backing up other key configuration files. They're commented because it's rarely needed compared to mirc.ini ; Right-click menus for nicklist, channel, status. default filename = popups.ini ; var %file $readini($mircini,pfiles,n0) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; list of servers in ALt+E window. default filename = servers.ini ; var %file $readini($mircini,files,servers) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; users tab of Alt+R editor. default filename = users.ini ; var %file $readini($mircini,rfiles,n0) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; variables tab of Alt+R editor. default filename = vars.ini ; var %file $readini($mircini,rfiles,n1) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; commands for OPTIONS/connect/options/perform. Filename is always perform.ini ; var %file perform.ini | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; Alt+U 'url catcher' default filename = urls.ini ; var %file $readini($mircini,files,urls) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; Users tab of Address-Book. default filename = addrbk.ini ; var %file $readini($mircini,files,addrbk) | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) ; Control tab of Address-Book. Filename is always control.ini ; var %file control.ini | if ($file(%file).size) copy -o $qt(%file) $qt($+($remove($nofile(%file),$mircdir),$nopath(%file),_,%dow,_,%weekday,.bak)) inc %now | set %mIRCiniBackup.PrevBackup %mIRCiniBackup.NewestBackup | set %mIRCiniBackup.NewestBackup $ctime } if ((%now) || (%new.interval != %mIRCiniBackup.interval) || (!$timer(mIRCiniBackup))) .timermIRCiniBackup -oi 0 %new.interval mIRCiniBackup $calc(%new.interval /3600) echo -sgc info mirc.ini backups at $duration(%mIRCiniBackup.interval) intervals. $iif(%mIRCiniBackup.interval != %new.interval,Overridden to $duration(%new.interval) *) $iif(%mIRCiniBackup.NewestBackup , Newest Backup $duration($calc($ctime - %mIRCiniBackup.NewestBackup)) ago $iif(%mIRCiniBackup.PrevBackup,* Backup before that $duration($calc($ctime - %mIRCiniBackup.PrevBackup)) ago)) echo -sgc info To restore: 1. Quit mIRC 2. copy one of these $findfile($mircdir,$+($nopath($mircini),_*.bak),0,1,echo -sg $asctime($file($1-).mtime) $chr(22) $1- $chr(22) $iif($asctime($file($1-).mtime,mm.dd.yyyy) == $asctime($ctime,mm.dd.yyyy),*today)) backups on top of $mircini 3. Copy all somewhere safe 4. Restart mIRC echo -sg %sc =/=/=/=/=/=/= Next Backup scheduled in $duration($timer(mIRCiniBackup).secs) @ $time($calc($ctime + $timer(mIRCiniBackup).secs)) * Force too-soon backup now and change interval: /mIRCiniBackup now 4 hours $chr(3) if (($ctimer == mIRCiniBackup) || ($ctimer == $null)) return var %i $timer(0) | while (%i) { if ($timer(%i) == $ctimer) { timer $+ %i off | return } | dec %i } } on *:unload:{ unset %mIRCiniBackup.* | timermIRCiniBackup off | echo -sgc info $nopath($script) unloaded. Thanks for trying it out. }
Changelog:
v1.1 added control.ini to commented-out list of *.ini settings files that could ooptionally be backed up.
v1.1 added control.ini to commented-out list of *.ini settings files that could ooptionally be backed up.
Review: entropy
This is great! Especially if your mIRC ini ever gets corrupted etc. Great job maroon!
This is great! Especially if your mIRC ini ever gets corrupted etc. Great job maroon!