Sunday, 28 June 2015

Solving Windows Update issue after restoring with Acronis

Following on from my recent post about the "Application not found" error message, it seems the system was not fully fixed.

One thing I omitted mentioning was that a few other fixes were tried beforehand, and to make sure we could get back to the previous state, a disk image was created using Acronis software.

Once it was realised the other 'fixes' hadn't helped, the Acronis backup was restored and the final fix (as described here) was performed.

Whilst testing everything was working, I noticed that Windows Update would not run, saying the service was not started. In fact the service wouldn't start even if I tried to run it manually.

Again here there were various forum posts on the subject, but eventually I found one which did actually fix it for this system.

So if you are having similar issues after restoring from an Acronis backup, try the following:

The backup should have been done on the disk level. When running restore make sure to also check the box for "restore system signature" which is hidden at the bottom of the page.

Once restored follow the steps on this page:

https://support.microsoft.com/en-us/kb/971058

I found the automatic 'Fix-it' tool didn't even run, so followed the steps part way down the page under the heading "Manually reset Windows Update components".

I followed the steps (skipping number 4 as it suggests for the first time) and when running all the commands on step 6 there were a few which came up with error messages. However, I kept on going through the list of commands.

When I got to step number nine the command to start cryptsvc came back saying it was already started. I continued, and installed the Windows Update Component from here.

Once the machine was rebooted, I went into Windows Update and it no longer showed a red cross, rather one critical and about 6 optionals to install. Here there was also a slight issue, I could not click install, as it said Windows was already running an update.

After another reboot the updater worked fine, and the system looks like it's in great condition. This is when it is definitely recommended to run a full backup (this was on a Lenovo machine, so we used their OneKey backup software that was already installed).

Hopefully anyone else with similar problems can resolve them easily by following this post.

Thursday, 25 June 2015

Solving "Application Not Found" for Control Panel after installing File Manager

Have you ever wanted a better way of moving files around on Windows?

As far back as I can remember one of the main requirements I had was for a dual-pane view so that copying and pasting is much easier, and opening with right click will show you your favourite folders.

As you might have guessed, this is not possible in Windows without installing some add-on or third-party program.

One of the programs I used to use was called PowerDesk. It did exactly what I wanted and was pretty reliable.

However times move on, and recently I was called to help out someone who had tried to install PowerDesk on their Windows 7 machine (64bit) after copying the file over from XP.

Of course the installation failed. But worse, it was no longer possible to open Control Panel, and some other programs through the Start Menu.

When you clicked, a popup would appear stating "Application not found" and then a long list of letters and numbers.

After quite a bit of searching, a workaround was found that would allow them to be opened, as long as you went through Windows Explorer first, and always right clicked what you wanted and selected "open in new window".

This workaround was long-winded but worked for most things. Except for add/remove programs, which is exactly where I wanted to go to make sure PowerDesk was uninstalled.

Some other sites suggested running a registry fix of code which was tried but also to no avail.

The Windows tool for checking and fixing system files was also suggested and tried, but no luck (run by hitting Start - and then typing "cmd" in the search bar, and then right clicking and selecting "run as Administrator" and once the commandline has opened type the following and hit Enter):

sfc /scannow

Eventually in an obscure forum I found a hint, that mentioned using the tool CCleaner (https://www.piriform.com/ccleaner/download).

Upon downloading the free version and running it, I took a look at the Registry Cleaner part of the tool. Clicking on "Scan now" it found a variety of issues. I scrolled through them briefly and one caught my eye - it was for PDexplorer (or something similar). This sounded promising (PD is short for PowerDesk here).
I left everything checked and ran "Fix Selected Issues".

After that the machine was rebooted and voila - no more issues with control panel or any the linked programs.

Hopefully this post will help someone else in a similar situation before resorting to a full factory reset.

Sunday, 22 February 2015

MySQL (safe) Binlog Removal

We have a MySQL Master-Slave setup, which has been running for many years without issue.

Recently, the disk space on the Master has been filling up with the binlog files, and so I started looking for a way to automate the process of removing old ones.

Here some background info first:

MySQL on the Master has files named eg mysql-bin.002465

These are rotated once a day, and as they have sizes of 100-500MB and quickly use up the free diskpace on the server.

However, these files are used by any MySQL slaves that point to this master.
If there are no network or hardware issues, the slave is normally up to speed with the master and so the delay behind the master is normally 0s.

If this is the case, then any files not currently being used can be removed without a problem.

However, if there has been (network/hardware) issues with the slave, then it could be many seconds or even hours behind the master, and therefore still using an older binlog file.

If an old binlog file is removed before a slave has finished processing it, the slave cannot continue and breaks consistency with the master, so it is important to make sure that only the files that have been finished by the slave are removed.

Removing shouldn't be done by deleting files, as the mysq-bin.index keeps track of files used, and deleting them doesn't remove them from this list.
The correct way to remove them is from within MySQL run the command:
mysql>PURGE BINARY LOGS TO 'mysql-bin.002499'
where mysql-bin.002499 is the filename on the master that the slave is currently using (ie has already processed the files before it).

In order to find out where the slave is up to in the binlog files, this MySQL command needs to be run on the Slave:
mysql>SHOW SLAVE STATUS\G
In amongst all of the data that comes out is the line:
Relay_Master_Log_File: mysql-bin.002499
This is the current file that is being processed by this slave.

So, a solution is needed to find the filename from the output line of a command on the MySQL Slave, and to pass that into a command for the MySQL Master to purge the files until that point.

After a bit of research, the following solution was found:
#!/bin/bash
eval `{ echo "mysql -uroot -e "; echo "'PURGE BINARY LOGS TO \""; mysql -h 192.168.0.251 -uroot -e 'SHOW SLAVE STATUS\G' | grep 'Relay_Master_Log_File' | cut -c30-; echo "\"';"; } | sed ':a;N;$!ba;s/\n//g'`
 This is saved as the file purge-mysql-logs-after-slave.sh in the /root directory with chmod +x to make it executable.
To schedule it daily, it is added to crontab like this:
# m h  dom mon dow   command
30 20 * * * /root/purge-mysql-logs-after-slave.sh
and so runs at 8.30pm every day (backup of mysql happens 9pm).
This is important as otherwise we will be removing all binary logs with data in, as the backup flushes the logs, creating this creates a new log file. Doing this before the backup happens means the purge leaves the current full binlog in tact, and the backup causes a new one to be created. Therefore there will always be 2 binlogs on the master at any time.