Introduction: Protect Your Ideas, Protect Your Work
I lost data some days ago through a PC crash. One day's work was lost. :/
- I save my data in the cloud to prevent a hard disk defect.
I use a versioning software so I can restore older versions of my work.
I make a backup every day.
But this time I lost my current data before backup. And a temporary file for recovery was also destroyed during the crash.
I would like to show you how I will avoid such data loss in the future.
(This solution is suitable for window systems.)
Step 1: What You Will Need...
You do not have to buy what you need.
- You need administrator rights
An editor, such as Notepad++ or the editor of Windows.
Step 2: Create a Batch File
I have a plan ;)
If you are a programmer or a book author or an picture editor, it is important to have very short backup distances. Maybe even a minute... I want an 10 minutes-backup in different directories so that nothing is overwritten.
First, we need a batch file that starts a back-up program. Windows has its own back-up program called Robocopy. Robocopy is command-line-based and can only be executed in a CMD window. (DOS-Box)
Now it is somewhat difficult, because I am German and have a German Windows. But let's see ...
Open an editor of your choice nd create a file named "backup.bat". The name is unimportant and can be chosen freely.
The command line for Robocopy is as follows:
Robocopy - source - target - files to be backed up - parameter
My batch file looks like:
- set quelle=D:\Projekte
- set ziel=D:\Datensicherung\RoboCopy\Backup_%time:~3,1%0
- robocopy "%quelle%" "%ziel%" *.c /mir /maxage:1
It is not necessary to use variables, but makes the command line clearer. It means the following:
- set quelle= This is the directory of your data. You can also use "source" or what ever you want instead of "quelle". It's your decision.
- set ziel= This is the target of your data backup. You can also use "target" or what ever you want instead of "ziel". It's your decision.
A new directory is created every 10 minutes. So a total of 6 directories. This is done by the directory description:
Backup is the first part of the name, than enclose the time with %
%time:~3,1%0 means: Take the current time and extract the first digit of the minute and add a 0.
i.e. time is 12:10:34 this means: 0=1, 1=2, 2=:, 3=1, 4=0, 5=:, 6=3, 7=4
3 digit = 1, show only one digit, add a 0 = 3,1%0 . That makes: 00, 10, 20, 30, 40, 50.
%time:~0,2% means, take the current time, extract the left digit of the hours and use 2 digits. (0-12/24)
%time:~3,2% means, take the current time, extract the left digit of the minutes and use 2 digits (0-59)
You can append the command "Pause" -> "wait" (?) command so that the window does not close automatically.
Save this batch file to a location of your choice. Start the file and see what happens. It should looks like the screenshot above and one directory should be created at the target place.
Step 3: The Task Scheduler (part1)
Windows has a task scheduler, can be found under System / Management.(?)
In German, this calls Windows-Verwaltungsprogramme -> Aufgabenplanung. Otherwise, ask the Windows Assistant for Task Scheduler.
Start the task scheduler. (I have attached an English-language screenshot.)
On the right, select Create Task... And you can see the window on picture 2.
- Give the task a name and a description. (if you want)
- The other details in this window can remain as they are.
Step 4: The Task Scheduler (part 2)
Select the Trigger tab.
- Select "Nach einem Zeitplan" (on a schedule) (the first selection)
- Select "Einmal" (one time) and enter current date and time.
- Select "Wiederholen jede:" (repeat task every) 10 Minutes.
- Select "Für die Dauer von:" (for a duration of) "sofort" (Indefinitely)
- Select "Ablaufen" (expire) if you want to set an end date/time
- Select "Aktiviert" (Enabled)
Step 5: The Task Scheduler (part 3)
Select the Action tab:
- Select "Aktion: Programm starten" (Action: Start a program)
- Under Program/Script enter the path and name of your batch file. (backup.bat)
No further information is required.
Step 6: The Task Scheduler (part 4)
Select the Conditions tab:
I have not specified any conditions, but if you use an Laptop, you could use some conditions...
Step 7: The Task Scheduler (part 5)
Select the Settings tab:
Look at these details carefully. Here you can enter something, if something does not work.
By default, settings 1,4 and 5 are selected and it´s a good choice. I also chose point 2. Take a look at the screenshot.
I think at this point it is not necessary to explain anything.
Step 8: The Final
Did you use the break (Pause / wait) in your batch file?
Did you save your new task?
Ok, on the right side, you see a RUN command. Select your task and let him run....
The command window appears and if the pause is included, the window remains open until you close it. Later you should modify your batch so you do not always have to close the window by hand.
A new directory, depending on the time was created in your target directory.
After an hour, the Task created 6 directories and stored your data that was not older than one day.
Wrong programming decisions are no longer a problem.
System crashes are no longer a problem.
But this method should not replace your normal backup and versioning!
Be warned and protect your ideas and work.