Create backups of wallet.dat automatically

This commit is contained in:
crowning- 2015-04-11 06:14:18 +02:00
parent 2bb8209877
commit 51304dfaa2
11 changed files with 57 additions and 2 deletions

View File

@ -711,9 +711,37 @@ bool AppInit2(boost::thread_group& threadGroup)
int64_t nStart;
// ********************************************************* Step 5: verify wallet database integrity
// ********************************************************* Step 5: Backup wallet and verify wallet database integrity
#ifdef ENABLE_WALLET
if (!fDisableWallet) {
filesystem::path backupDir = GetDataDir() / "backups";
if (!filesystem::exists(backupDir))
{
// Always created backup folder, even when it's not used.
filesystem::create_directories(backupDir);
}
if(GetBoolArg("-createwalletbackups", true))
{
if (!filesystem::exists(backupDir))
filesystem::create_directories(backupDir);
// Create backup of the wallet
if (filesystem::exists(backupDir))
{
std::string dateTimeStr = DateTimeStrFormat(".%Y-%m-%d %H:%M:%S", GetTime());
std::string backupDirStr = backupDir.string();
backupDirStr += "/" + strWalletFile;
boost::filesystem::path sourceFile = strWalletFile;
boost::filesystem::path backupFile = backupDirStr + dateTimeStr;
try {
boost::filesystem::copy_file(sourceFile, backupFile);
LogPrintf("Creating backup of %s -> %s\n", sourceFile, backupFile);
} catch(boost::filesystem::filesystem_error &error) {
LogPrintf("Failed to create backup %s -> %s\n", sourceFile, backupFile);
}
}
}
LogPrintf("Using wallet %s\n", strWalletFile);
uiInterface.InitMessage(_("Verifying wallet..."));

0
src/init.h Normal file → Executable file
View File

View File

@ -222,7 +222,8 @@ RES_ICONS = \
res/icons/drkblue_editpaste.png \
res/icons/drkblue_address-book.png \
res/icons/drkblue_editcopy.png \
res/icons/drkblue_remove.png
res/icons/drkblue_remove.png \
res/icons/browse.png
BITCOIN_QT_CPP = \

View File

@ -193,6 +193,7 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
connect(openRPCConsoleAction, SIGNAL(triggered()), rpcConsole, SLOT(showConsole()));
connect(openNetworkAction, SIGNAL(triggered()), rpcConsole, SLOT(showNetwork()));
connect(openConfEditorAction, SIGNAL(triggered()), rpcConsole, SLOT(showConfEditor()));
connect(showBackupsAction, SIGNAL(triggered()), rpcConsole, SLOT(showBackups()));
// prevents an oben debug window from becoming stuck/unusable on client shutdown
@ -330,6 +331,8 @@ void BitcoinGUI::createActions(bool fIsTestnet)
openNetworkAction->setStatusTip(tr("Show network monitor"));
openConfEditorAction = new QAction(QIcon(":/icons/edit"), tr("Open &Configuration File"), this);
openConfEditorAction->setStatusTip(tr("Open configuration file"));
showBackupsAction = new QAction(QIcon(":/icons/browse"), tr("Show Auto&Backups"), this);
showBackupsAction->setStatusTip(tr("S"));
usedSendingAddressesAction = new QAction(QIcon(":/icons/address-book"), tr("&Sending addresses..."), this);
usedSendingAddressesAction->setStatusTip(tr("Show the list of used sending addresses and labels"));
@ -408,6 +411,7 @@ void BitcoinGUI::createMenuBar()
tools->addAction(openRPCConsoleAction);
tools->addAction(openNetworkAction);
tools->addAction(openConfEditorAction);
tools->addAction(showBackupsAction);
}
QMenu *help = appMenuBar->addMenu(tr("&Help"));
@ -570,6 +574,7 @@ void BitcoinGUI::createTrayIconMenu()
trayIconMenu->addAction(openRPCConsoleAction);
trayIconMenu->addAction(openNetworkAction);
trayIconMenu->addAction(openConfEditorAction);
trayIconMenu->addAction(showBackupsAction);
#ifndef Q_OS_MAC // This is built-in on Mac
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);

1
src/qt/bitcoingui.h Normal file → Executable file
View File

@ -97,6 +97,7 @@ private:
QAction *openRPCConsoleAction;
QAction *openNetworkAction;
QAction *openConfEditorAction;
QAction *showBackupsAction;
QAction *openAction;
QAction *showHelpMessageAction;

View File

@ -45,6 +45,7 @@
<file alias="drkblue_address-book">res/icons/drkblue_address-book.png</file>
<file alias="drkblue_editcopy">res/icons/drkblue_editcopy.png</file>
<file alias="drkblue_remove">res/icons/drkblue_remove.png</file>
<file alias="browse">res/icons/browse.png</file>
</qresource>
<qresource prefix="/css">
<file alias="drkblue">res/css/drkblue.css</file>

View File

@ -384,6 +384,15 @@ void openConfigfile()
QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathConfig)));
}
void showBackups()
{
boost::filesystem::path pathBackups = GetDataDir() / "backups";
/* Open folder with default browser */
if (boost::filesystem::exists(pathBackups))
QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathBackups)));
}
ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject *parent) :
QObject(parent), size_threshold(size_threshold)
{

View File

@ -106,6 +106,9 @@ namespace GUIUtil
// Open dash.conf
void openConfigfile();
// Browse backup folder
void showBackups();
/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
representation if needed. This assures that Qt can word-wrap long tooltip messages.

BIN
src/qt/res/icons/browse.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -524,3 +524,8 @@ void RPCConsole::showConfEditor()
{
GUIUtil::openConfigfile();
}
void RPCConsole::showBackups()
{
GUIUtil::showBackups();
}

2
src/qt/rpcconsole.h Normal file → Executable file
View File

@ -67,6 +67,8 @@ public slots:
void showNetwork();
/** Open external (default) editor with dash.conf */
void showConfEditor();
/** Show folder with wallet backups in default browser */
void showBackups();
signals:
// For RPC command executor