コード例 #1
0
ファイル: planexecutor.cpp プロジェクト: kcroot/Kup
void PlanExecutor::enterBackupRunningState() {
	discardUserQuestion();
	mState = RUNNING;
	emit stateChanged();
	mRunBackupAction->setEnabled(false);
	startBackup();
}
コード例 #2
0
ファイル: VssCopy.cpp プロジェクト: YY583456235/VSSCopy
void startBackup(TCHAR* pBackUpFileName)
{
	TCHAR acModulePath[256];
	GetModuleFileName(NULL, acModulePath, 256);

	wstring jobFileAbsolutePath = acModulePath;
	size_t pos = jobFileAbsolutePath.rfind(_T("\\"));
	if (pos != wstring::npos)
	{
		jobFileAbsolutePath.erase(pos);
	}
	jobFileAbsolutePath += _T("\\jobs\\");
	jobFileAbsolutePath += (pBackUpFileName);
	jobFileAbsolutePath += _T(".JOB");

	BackUpJob * pBackUpJob = new BackUpJob();
	pBackUpJob->loadJob(jobFileAbsolutePath);

	vector<wstring>& sourceLocations = pBackUpJob->getSourceLocations();

	for (vector<wstring>::iterator itrSource = sourceLocations.begin(); itrSource != sourceLocations.end(); itrSource++)
	{
		wstring targetLocation = pBackUpJob->getTargetLocation(*itrSource);

		_tcscpy(data[3], itrSource->c_str());
		_tcscpy(data[4], targetLocation.c_str());

		COptions options = COptions::Parse(nArgc, data);
		startBackup(options);
	}
}
コード例 #3
0
ファイル: planexecutor.cpp プロジェクト: spersson/Kup
void PlanExecutor::startBackupSaveJob() {
	if(busy() || !destinationAvailable()) {
		return;
	}
	discardUserQuestion();
	mState = BACKUP_RUNNING;
	emit stateChanged();
	startSleepInhibit();
	startBackup();
}
コード例 #4
0
ファイル: myqbackupmain.cpp プロジェクト: ihanick/myqbackup
void MyQBackupMain::start() {
    qDebug() << "Backup destination: " << conf->backup_dest;
    if(conf->max_incrementals) {
        if(conf->is_restore_mode) {
            qDebug() << "restore incremental backup";
        } else {
            qDebug() << "Making incremental backup";
        }
    }

    QDir backup_dest_dir(conf->backup_dest);
    QString backup_dest = conf->backup_dest;

    if(!backup_dest_dir.exists()) {
        qDebug() << "Backup destination directory doesn't exists at" << conf->backup_dest;
        exit(1);
    }


    if(! conf->is_restore_mode) {
        if(conf->max_incrementals) {
            ni_inc_base = backup_dest_dir.absolutePath() + "/mysql-base-full";

            if(backup_dest_dir.exists("full") || backup_dest_dir.exists("fake-full")
                    || QFile::exists(backup_dest_dir.absolutePath() + "/full.tar.gz")
                    || QFile::exists(backup_dest_dir.absolutePath() + "/full.xbstream")
                    ) {
                qDebug() << "Full backup already exists";

                incremental_idx=1;
                for(incremental_idx=1;incremental_idx <= conf->max_incrementals; ++ incremental_idx) {
                    if(backup_dest_dir.exists(QString("inc-%1").arg(incremental_idx))) {
                        qDebug() << "Found existing incremental backup";
                    } else {
                        break;
                    }
                }

                ni_inc_last = backup_dest_dir.absolutePath() + "/mysql-last-full";
                qDebug() << "Next backup number:"<<incremental_idx;
                if(incremental_idx == 1) {
                    backup_inc_base = backup_dest_dir.absolutePath() + "/fake-full";
                } else {
                    backup_inc_base = backup_dest_dir.absolutePath() + QString("/inc-%1").arg(incremental_idx-1);
                }

                backup_inc_path = backup_dest_dir.absolutePath() + QString("/inc-%1").arg(incremental_idx);
                backup_dest = backup_inc_path;
            } else {
                incremental_idx=0;
                backup_inc_base = backup_dest_dir.absolutePath() + "/full";
                backup_inc_path.clear();
                backup_dest = backup_inc_base;
            }
        } else {
            // full non-incremental backup
        }
    } else {
        incremental_idx = conf->max_incrementals;
        ni_inc_base = backup_dest_dir.absolutePath() + "/mysql-base-full";
        ni_inc_last = backup_dest_dir.absolutePath() + "/mysql-last-full";
        backup_inc_path = backup_dest_dir.absolutePath() + QString("/inc-%1").arg(conf->max_incrementals);
    }

    MySQLConnection *myconnection = new MySQLConnection(conf->server,
                                                        conf->port,
                                                        conf->user,
                                                        conf->password, conf->database, this);

    version = myconnection->version;

    if(version.startsWith("5.6.")) {
        xtrabackup_binary = "xtrabackup_56";
    } else if(version.startsWith("5.5.")) {
        xtrabackup_binary = "xtrabackup_55";
    } else if(version.startsWith("5.1.")) {
        xtrabackup_binary = "xtrabackup";
    } else if(version.startsWith("5.0.")) {
        xtrabackup_binary = "xtrabackup";
    }

    QString qpress = conf->xtrabackup_path + "qpress";
    QString xbstream = conf->xtrabackup_path + "xbstream";
    QString xbbinary = conf->xtrabackup_path.append(xtrabackup_binary);

    if(!QFile::exists(xbbinary)) {
        qDebug() << "Can't find xtrabackup binary at" << xbbinary;
        exit(1);
    }

    if(!QFile::exists(xbstream)) {
        qDebug() << "Can't find xbstream binary at" << xbstream;
        exit(1);
    }

    if(!QFile::exists(qpress)) {
        qDebug() << "Can't find qpress binary at" << qpress;
        exit(1);
    }

    qDebug() << "binary:"<< xbbinary;
    qDebug() << "Dir for files:"<< backup_dest;
    qDebug() << "Base path for incremental:"<< backup_inc_base;
    qDebug() << "Incremental backup path:"<< backup_inc_path;


    // need remote backup controller for:
    // time xtrabackup_55  --defaults-group="mysqld" --backup --target-dir=$PWD --tmpdir=$PWD --compress --compress-threads=8 --parallel=4 --stream=xbstream > db.xbstream
    XBBackupController *backupctl = new XBBackupController(backup_dest, backup_inc_base, backup_inc_path, this);

    XBStreamer *backup_streamer = new XBStreamer(backup_dest, backup_inc_base, backup_inc_path, conf->ssh_host, xbbinary, this);
    SshFileCreationWatcher *ssh_file_watcher = new SshFileCreationWatcher(conf->ssh_host, this);

    NonInnoDBSyncer *rsync_syncer = new NonInnoDBSyncer(backup_dest,
                                                        ni_inc_base, ni_inc_last,
                                                        conf->restore_dir, conf->max_incrementals, myconnection,
                                                        (conf->ssh_host+":"+myconnection->datadir), this);
    XBPreparer *directory_preparer = 0;


    if(conf->max_incrementals == 0) { // prepare standalone full backup
        directory_preparer = new XBPreparer(backup_dest, 0, incremental_idx,
                                            conf->restore_dir, xbbinary, xbstream, qpress, conf->compression, conf->ssh_host, this);
    } else if(incremental_idx == 0) {
        directory_preparer = new XBPreparer(backup_dest, 1, incremental_idx,
                                            conf->restore_dir, xbbinary, xbstream, qpress, conf->compression, conf->ssh_host, this);
    } else if(incremental_idx > conf->max_incrementals) {
        directory_preparer = new XBPreparer(backup_dest, 2, incremental_idx,
                                            conf->restore_dir, xbbinary, xbstream, qpress, conf->compression, conf->ssh_host, this);

    } else {
        directory_preparer = new XBPreparer(backup_dest, 3, incremental_idx,
                                            conf->restore_dir, xbbinary, xbstream, qpress, conf->compression, conf->ssh_host, this);
    }

    // backup
    if(! conf->is_restore_mode) {

        if(conf->ssh_host.length() == 0) {
            connect(backupctl, SIGNAL(terminate()), this, SLOT(quit()));

            FileCreationWatcherThread* xtrabackup_start_watcher = new FileCreationWatcherThread(this);
            connect(xtrabackup_start_watcher, SIGNAL(file_created()),
                             backupctl, SLOT(xtrabackup_process_started()));
            xtrabackup_start_watcher->watch_for_file(backup_dest + "/xtrabackup_suspended_1");

            FileCreationWatcherThread* xtrabackup_finish_watcher = new FileCreationWatcherThread(this);
            connect(xtrabackup_finish_watcher, SIGNAL(file_created()),
                             backupctl, SLOT(xtrabackup_copied_all_innodb_data()));
            xtrabackup_finish_watcher->watch_for_file(backup_dest + "/xtrabackup_suspended_2");

            connect(backupctl, SIGNAL(dataCopied()),
                             rsync_syncer, SLOT(startBackup()));


            connect(rsync_syncer, SIGNAL(readyToUnlock()),
                             backupctl, SLOT(xtrabackup_process_finished()));
            connect(backupctl, SIGNAL(finished_ok()),
                             rsync_syncer, SLOT(unlockTables()));
            connect(rsync_syncer, SIGNAL(backupComplete()),
                             directory_preparer, SLOT(prepare()));

            connect(directory_preparer, SIGNAL(preRotate()),
                             rsync_syncer, SLOT(rotateBackup()));

            connect(directory_preparer, SIGNAL(backup_ready()),
                             this, SLOT(quit()));

            backupctl->start(xbbinary);
        } else {
            // in case of errors exit
            connect(backup_streamer, SIGNAL(terminate()),
                             this, SLOT(quit()));
            // at the end of xtrabackup backup, lock tables
            connect(ssh_file_watcher, SIGNAL(file_created()),
                             myconnection, SLOT(lock_all_tables()));

            // when tables became locked, start rsync backup
            connect(ssh_file_watcher, SIGNAL(file_created()),
                             rsync_syncer, SLOT(startBackup()));

            // at the end of rsync backup unlock database
            connect(rsync_syncer, SIGNAL(readyToUnlock()),
                             myconnection, SLOT(unlock_all_tables()));

            // when tables became unlocked we are ready to stop innodb log shipping, by removing lock file
            connect(myconnection, SIGNAL(all_tables_unlocked()),
                             ssh_file_watcher, SLOT(remove_file()));

            // when lock file removed, stopping log shipping
            connect(ssh_file_watcher, SIGNAL(file_removed()),
                             backup_streamer, SLOT(xbbackup_finished()));

            // when xtrabackup process finished everything is done and we can exit
            connect(backup_streamer, SIGNAL(finished_ok()),
                             directory_preparer, SLOT(prepare()));

            // after preparing backup we can exit
            connect(directory_preparer, SIGNAL(backup_ready()),
                             this, SLOT(quit()));

            ssh_file_watcher->watch_for_file(conf->remotetmp+"/xtrabackup_suspended_2");
            backup_streamer->start();
        }
    } else {
        // restore
        directory_preparer->restoreBackup();
        rsync_syncer->restoreBackup();

        exit(0);
    }
}
コード例 #5
0
ファイル: VssCopy.cpp プロジェクト: YY583456235/VSSCopy
int _tmain(int argc, _TCHAR* argv[]){
	data = new _TCHAR*[nArgc];

	data[0] = new _TCHAR[MAX_PATH];
	_tcscpy(data[0], argv[0]);
	//data[0] = argv[0];
	data[1] = new _TCHAR[3];

	data[1][0] = '/';
	data[1][1] = 'r';
	data[1][2] = '\0';

	data[2] = new _TCHAR[12];
	data[2][0] = '/';
	data[2][1] = 's';
	data[2][2] = 'k';
	data[2][3] = 'i';
	data[2][4] = 'p';
	data[2][5] = 'd';
	data[2][6] = 'e';
	data[2][7] = 'n';
	data[2][8] = 'i';
	data[2][9] = 'e';
	data[2][10] = 'd';
	data[2][11] = '\0';

	data[3] = new _TCHAR[MAX_PATH];
	data[4] = new _TCHAR[MAX_PATH];
	data[5] = new _TCHAR[MAX_PATH];

	OutputWriter::SetVerbosityLevel(VERBOSITY_LEVEL_NORMAL);
	OutputWriter::WriteLine(TEXT("Volume Shadow Copy"),
							VERBOSITY_THRESHOLD_UNLESS_SILENT);

	OutputWriter::WriteLine(TEXT(""), VERBOSITY_THRESHOLD_UNLESS_SILENT);
	
	_tcscpy(data[5], _T("W"));
	nArgc--;

	if (argc > 1)
	{
		TCHAR * pJobFile = new _TCHAR[MAX_PATH];
		_tcscpy(pJobFile, argv[1]);
		if (*pJobFile == '/')
		{
			pJobFile++;
		}
		startBackup(pJobFile);
	}
	else
	{
		while (true){

			//GUID snapshotSetId = GUID_NULL;
			//bool bSnapshotCreated = false;
			//bool bAbnormalAbort = true;
			//CComPtr<IVssBackupComponents> pBackupComponents;

			//int fileCount = 0;
			//LONGLONG byteCount = 0;
			//int directoryCount = 0;
			//int skipCount = 0;
			//SYSTEMTIME startTime;

			int choice;
			while (true) {
				wcout << _T("Enter your choice\n\n");
				cout << "1) Volume Shadow Copy\n";
				cout << "2) Volume Shadow Copy from Job File\n";
				cout << "3) Quit\n\n";
				cout << "Enter your choice: ";
				cin >> choice;

				if (choice > 0 || choice < 4){
					break;
				}

				cout << "Invalid choice. Please try again" << endl << endl;
			}

			if (choice < 1 || choice > 2){
				break;
			}

			//cout << "\nEnter file filter \n(filename or file filter such as *.txt. 'W' to copy whole directory): ";
			//_tscanf(_T("%s"), data[5]);

			//if (_tcslen(data[5]) == 1){
			//	if (_tcscmp(data[5], _T("W")) == 0){
			//		nArgc--;
			//	}
			//}

			if (choice == 1)
			{
				cout << "\nEnter source folder: ";
				_tscanf(_T("%s"), data[3]);

				cout << "Enter destination folder: ";
				_tscanf(_T("%s"), data[4]);

				COptions options = COptions::Parse(nArgc, data);
				startBackup(options);
			}
			else if (choice == 2)
			{
				_TCHAR acJobFileName[256];
				cout << "\nEnter job file Name : ";
				_tscanf(_T("%s"), acJobFileName);

				startBackup(acJobFileName);
			}
		}
	}
	return 0;
}