Skip to content

Commit

Permalink
Get the new life-preserver dataset reversion and single file reversio…
Browse files Browse the repository at this point in the history
…n working.
  • Loading branch information
Ken Moore committed Aug 13, 2013
1 parent 6328085 commit 7b2a986
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 21 deletions.
32 changes: 29 additions & 3 deletions life-preserver/LPBackend.cpp
Expand Up @@ -173,9 +173,35 @@ bool LPBackend::revertSnapshot(QString dataset, QString snapshot){
return (ret == 0);
}

bool LPBackend::browseSnapshot(QString dataset, QString snapshot){
//Not implemented yet
return false;
QString LPBackend::revertSnapshotFile(QString dsmountpoint, QString snapshot, QString filepath){
//Copy the given file from the snapshot back into the main dataset
// -- filepath: full path to the file in the snapshot directory

//Check that the file path is complete and the file exists
if(!QFile::exists(filepath)){
//invalid file given
return "";
}
//Generate the new file path
QString newfilepath = filepath.replace(dsmountpoint+"/.zfs/snapshot/"+snapshot, dsmountpoint);
if( QFile::exists(newfilepath) ){
//get the file extension
QString ext = newfilepath.section(".",-1);
newfilepath.chop(ext.length()+1);
newfilepath.append("-reversion."+ext);
int i=1;
//append a number to the end if a reversion file already exists
while(QFile::exists(newfilepath)){
newfilepath.chop(ext.length()+1);
newfilepath.append(QString::number(i)+"."+ext);
i++;
}
}
//perform the copy
bool ok = QFile::copy(filepath,newfilepath);
//return the path to the new file if the copy was successful
if(ok){ return newfilepath; }
else{ return ""; }
}

// ==================
Expand Down
2 changes: 1 addition & 1 deletion life-preserver/LPBackend.h
Expand Up @@ -26,7 +26,7 @@ class LPBackend{
static bool newSnapshot(QString dataset);
static bool removeSnapshot(QString dataset, QString snapshot);
static bool revertSnapshot(QString dataset, QString snapshot); //revert to given snapshot
static bool browseSnapshot(QString dataset, QString snapshot);
static QString revertSnapshotFile(QString dataset, QString snapshot, QString filepath);
//Replication Management
static bool setupReplication(QString dataset, QString remotehost, QString user, int port, QString remotedataset, int time);
static bool removeReplication(QString dataset);
Expand Down
6 changes: 4 additions & 2 deletions life-preserver/LPTray.cpp
Expand Up @@ -175,8 +175,10 @@ void LPTray::slotNewLogMessage(QString file){
}

void LPTray::slotTrayClicked(QSystemTrayIcon::ActivationReason reason){
if(reason == QSystemTrayIcon::Trigger){ startGUI(); }
else if( reason == QSystemTrayIcon::Context){
if(reason == QSystemTrayIcon::Trigger){
if(GUI->isVisible()){ GUI->hide(); }
else{ startGUI(); }
}else if( reason == QSystemTrayIcon::Context){
this->contextMenu()->popup(QCursor::pos());
}
}
Expand Down
39 changes: 29 additions & 10 deletions life-preserver/mainUI.cpp
Expand Up @@ -138,7 +138,6 @@ void mainUI::updateMenus(){
//Now set the items appropriately
revMenu->clear();
brMenu->clear();

if(ok){
//Reset the Menu Contents
QStringList subsets = HLIST[ds].subsets();
Expand All @@ -154,9 +153,6 @@ void mainUI::updateMenus(){
}
revMenu->addMenu(menu);
brMenu->addMenu(menu);
//
//revMenu->addAction( new QAction(snaps[i], this) );
//brMenu->addAction( new QAction(snaps[i], this) );
}
//Enable the buttons if appropriate
if(revMenu->isEmpty()){
Expand Down Expand Up @@ -229,31 +225,54 @@ void mainUI::slotRevertToSnapshot(QAction *act){
QString subset = info.section(":::",1,1);
QString snap = info.section(":::",2,2);
qDebug() << "Revert Clicked:" << ds << subset << snap;
return;
/*QString ds = getSelectedDS();
if(!ds.isEmpty()){
//Verify the reversion
if( QMessageBox::Yes == QMessageBox::question(this,tr("Verify Snapshot Reversion"),
QString(tr("Are you sure that you wish to revert %1 to the following snapshot?")).arg(ds)+"\n"+tr("WARNING: This will result in the loss of any data not previously backed up.")+"\n\n"+ds,
QString(tr("Are you sure that you wish to revert %1 to the selected snapshot?")).arg(subset)+"\n"+tr("WARNING: This will result in the loss of any data not previously backed up."),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){
//Perform the reversion
if( !LPBackend::revertSnapshot(ds,snapshot) ){
if( !LPBackend::revertSnapshot(ds+subset,snap) ){
//Error performing the reversion
qDebug() << " - Error:" << ds+subset << snap;
QMessageBox::warning(this,tr("Reversion Error"), tr("The snapshot reversion could not be completed successfully."));
}else{
//Good reversion
qDebug() << " - Revert Complete";
QMessageBox::information(this,tr("Reversion Success"), tr("The snapshot reversion was completed successfully."));
}
}
}*/
}
}

void mainUI::slotBrowseSnapshot(QAction *act){
QString info = act->whatsThis();
QString ds = info.section(":::",0,0);
QString subset = info.section(":::",1,1);
QString snap = info.section(":::",2,2);
qDebug() << "Browse Clicked:" << ds << subset << snap;
//Now let the user select a file within the snapshot to revert
QString snapPath = subset+"/.zfs/snapshot/"+snap+"/";
QString filepath = QFileDialog::getOpenFileName(this,tr("Revert a file"), snapPath, tr("Backup Files (*)") );
qDebug() << "File to revert:" << filepath;
//Check to make sure that it is a valid file (within the snapshot)
if(filepath.isEmpty() ){
qDebug() << " - Cancelled";
//action cancelled - do nothing
}else if(!filepath.startsWith(snapPath)){
qDebug() << " - Invalid File";
QMessageBox::warning(this, tr("Invalid Snapshot File"), tr("Please select a file from within the chosen snapshot that you wish to revert"));
}else{
//Revert the file
QString newfile = LPBackend::revertSnapshotFile(subset,snap,filepath);
if(newfile.isEmpty()){
//Error copying the new file over
qDebug() << " - Error copying file";
QMessageBox::warning(this, tr("Error Reverting File"), QString(tr("An error occurred while tring to revert the file %1. Please try again.")).arg(filepath));
}else{
//Let the user know the location of the reverted file
qDebug() << " - Successful reversion:" << newfile;
QMessageBox::information(this, tr("FIle Reverted"), QString(tr("The reverted file is now available at: %1")).arg(newfile) );
}
}
return;
}

Expand Down
1 change: 1 addition & 0 deletions life-preserver/mainUI.h
Expand Up @@ -9,6 +9,7 @@
#include <QDebug>
#include <QMessageBox>
#include <QCloseEvent>
#include <QFileDialog>

#include "LPBackend.h"
#include "LPWizard.h"
Expand Down
10 changes: 5 additions & 5 deletions life-preserver/mainUI.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>174</height>
<width>456</width>
<height>175</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -128,7 +128,7 @@
<item>
<widget class="QToolButton" name="tool_browse">
<property name="statusTip">
<string>Browse the files in a snapshot of the current dataset</string>
<string>Browse a snapshot and safely recover that version of a file</string>
</property>
<property name="text">
<string>Browse</string>
Expand All @@ -145,7 +145,7 @@
<item>
<widget class="QToolButton" name="tool_revert">
<property name="statusTip">
<string>Revert the selected dataset to a previous snapshot</string>
<string>Revert an entire data subset to a previous snapshot (overwrites all files)</string>
</property>
<property name="text">
<string>Revert</string>
Expand All @@ -169,7 +169,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<width>456</width>
<height>20</height>
</rect>
</property>
Expand Down

0 comments on commit 7b2a986

Please sign in to comment.