Created
June 18, 2012 08:36
-
-
Save XP1/2947495 to your computer and use it in GitHub Desktop.
Backup Opera: Backs up the files in an Opera profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<package> | |
<job id="backupOpera"> | |
<?job error="false" debug="false"?> | |
<script> | |
//<![CDATA[ | |
/* | |
* Copyright 2012 XP1 | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */ | |
(function (script, fileSystem) | |
{ | |
"use strict"; | |
function pad(number) | |
{ | |
return ((number >= 0 && number <= 9 ? "0" : "") + number); | |
} | |
function formatDate(date) | |
{ | |
return (date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate())); | |
} | |
function formatTime(date) | |
{ | |
return (pad(date.getHours()) + "-" + pad(date.getMinutes()) + "-" + pad(date.getSeconds())); | |
} | |
function formatDateTime(date) | |
{ | |
return (formatDate(date) + " " + formatTime(date)); | |
} | |
function sameFile(first, second) | |
{ | |
return (first.dateLastModified - second.dateLastModified === 0); | |
} | |
function getPath(path, appendage) | |
{ | |
var forwardSlashIndex = path.lastIndexOf("/"); | |
var backwardSlashIndex = path.lastIndexOf("\\"); | |
var greatestIndex = (forwardSlashIndex > backwardSlashIndex ? forwardSlashIndex : backwardSlashIndex); | |
var dotIndex = path.indexOf(".", (greatestIndex !== -1 ? greatestIndex + 1 : 0)); | |
return (dotIndex !== -1 ? (path.substring(0, dotIndex) + appendage + path.substring(dotIndex)) : (path + appendage)); | |
} | |
function backupFile(currentPath) | |
{ | |
var current = fileSystem.getFile(currentPath); | |
var backupPath = getPath(currentPath, " backup"); | |
if (fileSystem.fileExists(backupPath)) | |
{ | |
var backup = fileSystem.getFile(backupPath); | |
// Only move the backup file if it is different than the current file. | |
if (!sameFile(current, backup)) | |
{ | |
var backupDatePath = getPath(currentPath, " " + formatDateTime(new Date(backup.dateLastModified))); | |
if (!fileSystem.fileExists(backupDatePath)) | |
{ | |
backup.move(backupDatePath); | |
} | |
} | |
} | |
if (!fileSystem.fileExists(backupPath)) | |
{ | |
current.copy(backupPath); | |
} | |
} | |
function initialize() | |
{ | |
var paths = [ | |
"sessions/autosave.win", | |
"bookmarks.adr", | |
"wand.dat", | |
"notes.adr", | |
"speeddial.ini", | |
"search.ini", | |
"urlfilter.ini", | |
"browser.js" | |
]; | |
var i = null; | |
var length = paths.length; | |
for (i = 0; i < length; i += 1) | |
{ | |
backupFile(paths[i]); | |
} | |
} | |
initialize(); | |
script.quit(); | |
}(this.WScript, new this.ActiveXObject("Scripting.FileSystemObject"))); | |
//]]> | |
</script> | |
</job> | |
</package> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<RegistrationInfo> | |
<Date>2012-01-01T00:00:01</Date> | |
<Author>Administrator</Author> | |
</RegistrationInfo> | |
<Triggers> | |
<BootTrigger> | |
<Repetition> | |
<Interval>P3D</Interval> | |
<StopAtDurationEnd>false</StopAtDurationEnd> | |
</Repetition> | |
<ExecutionTimeLimit>PT30S</ExecutionTimeLimit> | |
<Enabled>true</Enabled> | |
</BootTrigger> | |
</Triggers> | |
<Principals> | |
<Principal id="Author"> | |
<GroupId>Users</GroupId> | |
<RunLevel>LeastPrivilege</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<IdleSettings> | |
<Duration>PT10M</Duration> | |
<WaitTimeout>PT1H</WaitTimeout> | |
<StopOnIdleEnd>true</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT30S</ExecutionTimeLimit> | |
<Priority>7</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>"\Backup Opera 1.00.wsf"</Command> | |
<WorkingDirectory>%APPDATA%\Opera\Opera\</WorkingDirectory> | |
</Exec> | |
</Actions> | |
</Task> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a folder for storing the script.
Right click on "raw" > Save Linked Content As... > Save the WSF file to your folder.
Next, save the XML file as "Backup Opera 1.00.xml".
When you save the XML file, make sure that you save the file encoding as UTF-16 (labeled "Unicode" in Notepad).
On
<Command>"\Backup Opera 1.00.wsf"</Command>
, make sure that you modify this line by adding the location of the script.On
<WorkingDirectory>%APPDATA%\Opera\Opera\</WorkingDirectory>
, you can change this line if your profile location is different.Start > All Programs > Accessories > Right click on "Command Prompt" > Run as administrator.
Change to the directory where the XML file is located.
Import the XML as a task:
If you want to delete the task, type:
This task is set up to run every 3 days.
After you have imported the task, you can configure the interval and schedule by using the task scheduler. To open the task scheduler, in the command prompt or in a Start > Run dialog, type: