Automating my PC maintenance tasks

Automate it by Gastev

Automate it by Gastev

Recently, I automated a few of my deployment processes. They were taking too much time to do and they were frankly boring. I managed automate everything including the database backup, putting the site in maintenance mode, creating the file package, sending the file package, extracting the file package on the server, preparing the database package and sending the database package.

Back at home, I was still doing my manual PC maintenance tasks. I finally got tired of it. I decided it was time to get productive and avoid those boring tasks.

There is two maintenance tasks I was doing regularly that needed more attention: defragmentation and backup. I started by looking for some usefull tools. For backup purposes, I did a few searches and I found that rdiff-backup suits all my needs. It is open source, built with Python, I can easy extend it if I need it and it is free. For defragmentation, I went to one of my favourite freeware site and found Auslogics Disk Defrag. It is free and includes a command line version. This is all I needed to get started.

Next comes the when. I asked myself when was it the most appropriate time to run those maintenance tasks. The best answer I could came up with was when I am not using my PC. Obviously, the PC has to be running to execute those tasks. I also wanted to run those tasks once a day.

I started to look at finding some idle time on my PC. Should I run those tasks when my screen saver starts ? When does my screen saver actually starts ? What is an idling computer ? I started to dig at that definition and I found out there is no definitive answer on that. There can be no interactive activity on my PC (i.e. the mouse is not moving and there no key strokes) but that does not mean there is no background process using all the CPU, memory, disk IO and network. I would not want my maintenance tasks to start at that time.

After that, I though about how I use my computer. I usually turn it on sometime after I come back from work and turn it off before going to sleep. A good opportunity to run those tasks would be just before it turns off. I found out Windows has a mechanism for shutdown scripts. I added my scripts there.

A few days later, I had to let my computer turned on for more than one day. It stroke me as a lightning. If I am leaving my PC turned on, my maintenance tasks will not be executed. I added a scheduled task to start my maintenance script at 4:50AM. Since I am usually not in front of my PC at that time and I do not mind the resource usage involved, I think it is a good compromise.

This sums up the process I went into to try to optimize those automated maintenance tasks. There is still one minor problem with this setup. Sometimes, I want to reboot my PC for some updates and I do not want to run the maintenance tasks. If you know a way to detect a reboot in the shutdown scripts or to add a switch somewhere in the shutdown process that I can detect with my scripts, let me know.

For your information, here are the batch scripts I am using.

set MYDEFRAGPATH=C:\Program Files\Auslogics\Auslogics Disk Defrag\cdefrag.exe
set DEFRAGLOGFILE=C:\Program Files\Auslogics\Auslogics Disk Defrag\daily-defrag-logs.txt
set DEFREGLOGHTML=C:\Program Files\Auslogics\Auslogics Disk Defrag\logs
echo ************************************* >> "%DEFRAGLOGFILE%"
echo Shutdown Daily Defrag: %DATE% %TIME% >> "%DEFRAGLOGFILE%"
echo ************************************* >> "%DEFRAGLOGFILE%"
"%MYDEFRAGPATH%" -c -log:"%DEFREGLOGHTML%" >> "%DEFRAGLOGFILE%" 2>&1
set BACKUPLOGFILE=D:\Backups\logs.txt
set RDIFFBACKUPPATH=C:\Program Files\rdiff-backup-1.2.8\rdiff-backup.exe
echo ************************************* >> "%BACKUPLOGFILE%"
echo Shutdown Backup: %DATE% %TIME% >> "%BACKUPLOGFILE%"
echo ************************************* >> "%BACKUPLOGFILE%"
"%RDIFFBACKUPPATH%" --force --remove-older-than 1M "D:/Backups/Documents and Settings"
"%RDIFFBACKUPPATH%" --exclude "C:/Documents and Settings/MyPC/Mes documents/Downloads" "C:/Documents and Settings" "D:/Backups/Documents and Settings" >> "%BACKUPLOGFILE%" 2>&1

Comments 4

  1. Rob wrote:

    Looks like you’ve put a lot of thought into this. I look forward to giving it a try.

    Posted 17 Sep 2011 at 4:22 pm
  2. Eel wrote:

    Walking in the presence of giants here. Cool thninkig all around!

    Posted 12 Dec 2011 at 3:59 am
  3. zaqrjhbs wrote:

    RS8s3Y aryqszikwmvx

    Posted 13 Dec 2011 at 4:09 am
  4. dlibmug wrote:

    Mm1O2r rsynkwxkuzdc

    Posted 14 Dec 2011 at 12:33 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *

CAPTCHA image