|
SystemTrade
2014-01-01 19:44:46
|
|
A happy, healthful and prosperous New Year to everyone and all the best for 2014!
This is the time when I backup my operative QuantShare account.
Why?
Because I want to have an account with "frozen" history that will not be impacted by future changes of index constituents, corporate actions etc.
Why not just copy the database folder?
Of course, symbols and their quotes as well as a lot of other information is stored in the database folder "\QuantShareFolder\Database\AccountName\"
But there is also some data outside this database folder:
in "\QuantShareFolder\Database\" we have files like "AccountName*.*" that contain information on symbol categories and others.
in "\QuantShareFolder\" we have a file "AccountName.xml" that contains information on the layout of the docking panel.
How to backup
Create your Destination Account ("Accounts > Add Account"), the account name you enter will be your destination account.
QuantShare will automatically select this new account.
Change back to your source account
(Accounts > Change Account, select source account, "Open")
Go to "Tools > Script Editor" copy the script below, change the line "string DestinationAccountName = "_Backup_" to your individual Destination account name that you have used for account creation
(MAKE SURE THAT YOU ENTER THE CORRECT DESTINATION ACCOUNT IN THE SCRIPT, OTHERWISE DATA MIGHT BE OVERWRITTEN!)
and execute the script.
Go to the destination account now (Accounts > Change Account, select destination account, "Open")
and you will see your quotes, symbols, categories, docking panels
// -------------- C# backup an entire account ------------------
using System.IO;
string DestinationAccountName = "_Backup_"; // edit according to your needs
bool AllowFileOverwrite = true;
string SourceAccountName = App.Main.GetAccountName();
string SourceUserDatabasePath = App.Main.GetUserDatabasePath();
string QSDatabasesPath = SourceUserDatabasePath.Substring(0, SourceUserDatabasePath.LastIndexOf(SourceAccountName));
string DestinationUserDatabasePath = QSDatabasesPath + DestinationAccountName;
// copy xml file
string QSPath = QSDatabasesPath.Substring(0, QSDatabasesPath.LastIndexOf("Database"));
File.Copy(QSPath + SourceAccountName + ".xml", QSPath + DestinationAccountName + ".xml", AllowFileOverwrite);
Global.Trace1("xml file copied");
// copy settings files
string[] SourceAccountSettingFiles = Directory.GetFiles(QSDatabasesPath, SourceAccountName + "*.*");
string[] DestinationAccountSettingFiles = new string[SourceAccountSettingFiles.Length];
for (int i = 0; i < SourceAccountSettingFiles.Length; i++)
{
DestinationAccountSettingFiles[i] = Path.GetDirectoryName(SourceAccountSettingFiles[i]) + "\\" + DestinationAccountName + SourceAccountSettingFiles[i].Substring(SourceAccountSettingFiles[i].LastIndexOf(SourceAccountName) + SourceAccountName.Length);
File.Copy(SourceAccountSettingFiles[i], DestinationAccountSettingFiles[i], AllowFileOverwrite);
};
Global.Trace1(SourceAccountSettingFiles.Length.ToString() + " settings files copied");
// copy Database files and folders
string[] SourceDatabaseFiles = Directory.GetFiles(SourceUserDatabasePath, "*.*", SearchOption.AllDirectories);
foreach (string SourceFile in SourceDatabaseFiles)
{
string DestinationFile = QSDatabasesPath + DestinationAccountName + SourceFile.Substring(SourceUserDatabasePath.Length);
if (!Directory.Exists(Path.GetDirectoryName(DestinationFile))) Directory.CreateDirectory(Path.GetDirectoryName(DestinationFile));
File.Copy(SourceFile, DestinationFile, AllowFileOverwrite);
}
Global.Trace1(SourceDatabaseFiles.Length.ToString() + " database files copied");
|
|