author | mickeyl <mickeyl> | 2004-11-04 15:12:01 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-04 15:12:01 (UTC) |
commit | 5f56ab623c99c12ce246f775e065632fbfbbfc1f (patch) (unidiff) | |
tree | 0035922070d36de69226bfcefc4d959b5a453f61 /noncore/settings/backup/backuprestore.cpp | |
parent | 18684ddb43d4d79304dee6b20ab62513ee50b883 (diff) | |
download | opie-5f56ab623c99c12ce246f775e065632fbfbbfc1f.zip opie-5f56ab623c99c12ce246f775e065632fbfbbfc1f.tar.gz opie-5f56ab623c99c12ce246f775e065632fbfbbfc1f.tar.bz2 |
- prepare for backing up root file systems (aka clone)
- add file headers
- add version to .pro
Diffstat (limited to 'noncore/settings/backup/backuprestore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 1748e8d..c944c6d 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -1,49 +1,75 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | =. | ||
4 | .=l. Copyright (c) 2002-2004 The Opie Team <opie-devel@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
1 | #include "backuprestore.h" | 29 | #include "backuprestore.h" |
2 | #include "errordialog.h" | 30 | #include "errordialog.h" |
3 | 31 | ||
4 | |||
5 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <qpe/qpeapplication.h> | ||
34 | #include <qpe/resource.h> | ||
35 | #include <qpe/config.h> | ||
6 | #include <opie2/odebug.h> | 36 | #include <opie2/odebug.h> |
7 | #include <opie2/ostorageinfo.h> | 37 | #include <opie2/ostorageinfo.h> |
8 | using namespace Opie::Core; | ||
9 | |||
10 | #include <opie2/ofiledialog.h> | 38 | #include <opie2/ofiledialog.h> |
11 | #include <opie2/owait.h> | 39 | #include <opie2/owait.h> |
40 | using namespace Opie::Core; | ||
12 | using namespace Opie::Ui; | 41 | using namespace Opie::Ui; |
13 | 42 | ||
14 | #include <qpe/qpeapplication.h> | ||
15 | #include <qpe/resource.h> | ||
16 | #include <qpe/config.h> | ||
17 | |||
18 | /* QT */ | 43 | /* QT */ |
19 | #include <qapplication.h> | 44 | #include <qapplication.h> |
20 | #include <qmultilineedit.h> | 45 | #include <qmultilineedit.h> |
21 | #include <qdir.h> | 46 | #include <qdir.h> |
22 | #include <qfile.h> | 47 | #include <qfile.h> |
23 | #include <qfileinfo.h> | 48 | #include <qfileinfo.h> |
24 | #include <qlistview.h> | 49 | #include <qlistview.h> |
25 | #include <qpushbutton.h> | 50 | #include <qpushbutton.h> |
51 | #include <qradiobutton.h> | ||
26 | #include <qheader.h> | 52 | #include <qheader.h> |
27 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
28 | #include <qcombobox.h> | 54 | #include <qcombobox.h> |
29 | #include <qlist.h> | 55 | #include <qlist.h> |
30 | #include <qregexp.h> | 56 | #include <qregexp.h> |
31 | #include <qtextstream.h> | 57 | #include <qtextstream.h> |
32 | #include <qtextview.h> | 58 | #include <qtextview.h> |
33 | #include <qlineedit.h> | 59 | #include <qlineedit.h> |
34 | #include <qstringlist.h> | 60 | #include <qstringlist.h> |
35 | 61 | ||
36 | /* STD */ | 62 | /* STD */ |
37 | #include <errno.h> | 63 | #include <errno.h> |
38 | #include <stdlib.h> | 64 | #include <stdlib.h> |
39 | #include <unistd.h> | 65 | #include <unistd.h> |
40 | #include <sys/stat.h> | 66 | #include <sys/stat.h> |
41 | #include <dirent.h> | 67 | #include <dirent.h> |
42 | 68 | ||
43 | #define HEADER_NAME 0 | 69 | #define HEADER_NAME 0 |
44 | #define HEADER_BACKUP 1 | 70 | #define HEADER_BACKUP 1 |
45 | #define BACKUP_LOCATION 2 | 71 | #define BACKUP_LOCATION 2 |
46 | 72 | ||
47 | #define EXTENSION ".bck" | 73 | #define EXTENSION ".bck" |
48 | 74 | ||
49 | const QString tempFileName = "/tmp/backup.err"; | 75 | const QString tempFileName = "/tmp/backup.err"; |
@@ -223,96 +249,110 @@ void BackupAndRestore::scanForApplicationSettings() | |||
223 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 249 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
224 | const QFileInfoList *list = d.entryInfoList(); | 250 | const QFileInfoList *list = d.entryInfoList(); |
225 | QFileInfoListIterator it( *list ); | 251 | QFileInfoListIterator it( *list ); |
226 | QFileInfo *fi; | 252 | QFileInfo *fi; |
227 | while ( (fi=it.current()) ) | 253 | while ( (fi=it.current()) ) |
228 | { | 254 | { |
229 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; | 255 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; |
230 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) | 256 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) |
231 | { | 257 | { |
232 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 258 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
233 | selectItem(newItem); | 259 | selectItem(newItem); |
234 | } | 260 | } |
235 | ++it; | 261 | ++it; |
236 | } | 262 | } |
237 | } | 263 | } |
238 | 264 | ||
239 | /** | 265 | /** |
240 | * The "Backup" button has been pressed. Get a list of all of the files that | 266 | * The "Backup" button has been pressed. Get a list of all of the files that |
241 | * should be backed up. If there are no files, emit and error and exit. | 267 | * should be backed up. If there are no files, emit and error and exit. |
242 | * Determine the file name to store the backup in. Backup the file(s) using | 268 | * Determine the file name to store the backup in. Backup the file(s) using |
243 | * tar and gzip --best. Report failure or success | 269 | * tar and gzip --best. Report failure or success |
244 | */ | 270 | */ |
245 | void BackupAndRestore::backup() | 271 | void BackupAndRestore::backup() |
246 | { | 272 | { |
273 | if ( cb_type_userdata->isChecked() ) | ||
274 | backupUserData(); | ||
275 | else | ||
276 | backupRootFs(); | ||
277 | } | ||
278 | |||
279 | |||
280 | void BackupAndRestore::backupRootFs() | ||
281 | { | ||
282 | QMessageBox::critical(this, "Message", "Not Yet Implemented", "Ok" ); | ||
283 | } | ||
284 | |||
285 | void BackupAndRestore::backupUserData() | ||
286 | { | ||
247 | QString backupFiles; | 287 | QString backupFiles; |
248 | if(getBackupFiles(backupFiles, NULL) == 0) | 288 | if(getBackupFiles(backupFiles, NULL) == 0) |
249 | { | 289 | { |
250 | QMessageBox::critical(this, "Message", | 290 | QMessageBox::critical(this, "Message", |
251 | "No items selected.",QString("Ok") ); | 291 | "No items selected.",QString("Ok") ); |
252 | return; | 292 | return; |
253 | } | 293 | } |
254 | 294 | ||
255 | OWait *owait = new OWait(); | 295 | OWait *owait = new OWait(); |
256 | Global::statusMessage( tr( "Backing up..." ) ); | 296 | Global::statusMessage( tr( "Backing up..." ) ); |
257 | owait->show(); | 297 | owait->show(); |
258 | qApp->processEvents(); | 298 | qApp->processEvents(); |
259 | 299 | ||
260 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 300 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
261 | 301 | ||
262 | QDateTime datetime = QDateTime::currentDateTime(); | 302 | QDateTime datetime = QDateTime::currentDateTime(); |
263 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 303 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
264 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 304 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
265 | 305 | ||
266 | outputFile += "/" + dateString; | 306 | outputFile += "/" + dateString; |
267 | 307 | ||
268 | QString t = outputFile; | 308 | QString t = outputFile; |
269 | int c = 1; | 309 | int c = 1; |
270 | while(QFile::exists(outputFile + EXTENSION)) | 310 | while(QFile::exists(outputFile + EXTENSION)) |
271 | { | 311 | { |
272 | outputFile = t + QString("%1").arg(c); | 312 | outputFile = t + QString("%1").arg(c); |
273 | c++; | 313 | c++; |
274 | } | 314 | } |
275 | 315 | ||
276 | // We execute tar and compressing its output with gzip.. | 316 | // We execute tar and compressing its output with gzip.. |
277 | // The error output will be written into a temp-file which could be provided | 317 | // The error output will be written into a temp-file which could be provided |
278 | // for debugging.. | 318 | // for debugging.. |
279 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; | 319 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; |
280 | outputFile += EXTENSION; | 320 | outputFile += EXTENSION; |
281 | 321 | ||
282 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) | 322 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) |
283 | .arg( getExcludeFile() ) | 323 | .arg( getExcludeFile() ) |
284 | .arg( backupFiles ) | 324 | .arg( backupFiles ) |
285 | .arg( outputFile.latin1() ) | 325 | .arg( outputFile.latin1() ) |
286 | .arg( tempFileName.latin1() ); | 326 | .arg( tempFileName.latin1() ); |
287 | 327 | ||
288 | odebug << commandLine << oendl; | 328 | odebug << commandLine << oendl; |
289 | 329 | ||
290 | int r = system( commandLine ); | 330 | int r = system( commandLine ); |
291 | 331 | ||
292 | owait->hide(); | 332 | owait->hide(); |
293 | delete owait; | 333 | delete owait; |
294 | 334 | ||
295 | //Error-Handling | 335 | //Error-Handling |
296 | if(r != 0) | 336 | if(r != 0) |
297 | { | 337 | { |
298 | perror("Error: "); | 338 | perror("Error: "); |
299 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 339 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
300 | 340 | ||
301 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" | 341 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Backup Failed!" ) + "\n" |
302 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) | 342 | + errorMsg, QString( tr( "Ok" ) ), QString( tr( "Details" ) ) ) ) |
303 | { | 343 | { |
304 | 344 | ||
305 | case 1: | 345 | case 1: |
306 | owarn << "Details pressed !" << oendl; | 346 | owarn << "Details pressed !" << oendl; |
307 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 347 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
308 | QFile errorFile( tempFileName ); | 348 | QFile errorFile( tempFileName ); |
309 | if ( errorFile.open(IO_ReadOnly) ) | 349 | if ( errorFile.open(IO_ReadOnly) ) |
310 | { | 350 | { |
311 | QTextStream t( &errorFile ); | 351 | QTextStream t( &errorFile ); |
312 | QString s; | 352 | QString s; |
313 | while ( !t.eof() ) | 353 | while ( !t.eof() ) |
314 | { // until end of file... | 354 | { // until end of file... |
315 | s += t.readLine(); // line of text excluding '\n' | 355 | s += t.readLine(); // line of text excluding '\n' |
316 | } | 356 | } |
317 | errorFile.close(); | 357 | errorFile.close(); |
318 | 358 | ||
@@ -422,88 +462,88 @@ void BackupAndRestore::rescanFolder(QString directory) | |||
422 | } | 462 | } |
423 | else | 463 | else |
424 | { | 464 | { |
425 | // If it is a backup file add to list. | 465 | // If it is a backup file add to list. |
426 | if(file->fileName().contains(EXTENSION)) | 466 | if(file->fileName().contains(EXTENSION)) |
427 | (void)new QListViewItem(restoreList, file->fileName()); | 467 | (void)new QListViewItem(restoreList, file->fileName()); |
428 | } | 468 | } |
429 | ++it; | 469 | ++it; |
430 | } | 470 | } |
431 | } | 471 | } |
432 | 472 | ||
433 | /** | 473 | /** |
434 | * Restore a backup file. | 474 | * Restore a backup file. |
435 | * Report errors or success | 475 | * Report errors or success |
436 | */ | 476 | */ |
437 | void BackupAndRestore::restore() | 477 | void BackupAndRestore::restore() |
438 | { | 478 | { |
439 | QListViewItem *restoreItem = restoreList->currentItem(); | 479 | QListViewItem *restoreItem = restoreList->currentItem(); |
440 | if(!restoreItem) | 480 | if(!restoreItem) |
441 | { | 481 | { |
442 | QMessageBox::critical(this, tr( "Message" ), | 482 | QMessageBox::critical(this, tr( "Message" ), |
443 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); | 483 | tr( "Please select something to restore." ),QString( tr( "Ok") ) ); |
444 | return; | 484 | return; |
445 | } | 485 | } |
446 | 486 | ||
447 | OWait *owait = new OWait(); | 487 | OWait *owait = new OWait(); |
448 | Global::statusMessage( tr( "Restore Backup..." ) ); | 488 | Global::statusMessage( tr( "Restore Backup..." ) ); |
449 | owait->show(); | 489 | owait->show(); |
450 | qApp->processEvents(); | 490 | qApp->processEvents(); |
451 | 491 | ||
452 | QString restoreFile = backupLocations[restoreSource->currentText()]; | 492 | QString restoreFile = backupLocations[restoreSource->currentText()]; |
453 | 493 | ||
454 | restoreFile += "/" + restoreItem->text(0); | 494 | restoreFile += "/" + restoreItem->text(0); |
455 | 495 | ||
456 | odebug << restoreFile << oendl; | 496 | odebug << restoreFile << oendl; |
457 | 497 | ||
458 | //check if backup file come from opie 1.0.x | 498 | //check if backup file come from opie 1.0.x |
459 | 499 | ||
460 | QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); | 500 | QString commandLine = QString( "tar -tzf %1 | grep Applications/backup/exclude" ).arg( restoreFile.latin1() ); |
461 | 501 | ||
462 | int r = system( commandLine ); | 502 | int r = system( commandLine ); |
463 | 503 | ||
464 | QString startDir; | 504 | QString startDir; |
465 | 505 | ||
466 | if( r != 0 ) //Applications/backup/exclude not found - old backup file | 506 | if( r != 0 ) //Applications/backup/exclude not found - old backup file |
467 | { | 507 | { |
468 | startDir = QString( "/" ); | 508 | startDir = QString( "/" ); |
469 | } else | 509 | } else |
470 | { | 510 | { |
471 | startDir = QDir::homeDirPath(); | 511 | startDir = QDir::homeDirPath(); |
472 | } | 512 | } |
473 | 513 | ||
474 | //unpack backup file | 514 | //unpack backup file |
475 | commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) | 515 | commandLine = QString( "cd %1 && tar -zxf %2 2> %3" ).arg( startDir ) |
476 | .arg( restoreFile.latin1() ) | 516 | .arg( restoreFile.latin1() ) |
477 | .arg( tempFileName.latin1() ); | 517 | .arg( tempFileName.latin1() ); |
478 | 518 | ||
479 | odebug << commandLine << oendl; | 519 | odebug << commandLine << oendl; |
480 | 520 | ||
481 | r = system( commandLine ); | 521 | r = system( commandLine ); |
482 | 522 | ||
483 | owait->hide(); | 523 | owait->hide(); |
484 | delete owait; | 524 | delete owait; |
485 | 525 | ||
486 | //error handling | 526 | //error handling |
487 | if(r != 0) | 527 | if(r != 0) |
488 | { | 528 | { |
489 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); | 529 | QString errorMsg= tr( "Error from System:\n" ) + (QString)strerror( errno ); |
490 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" | 530 | switch( QMessageBox::critical(this, tr( "Message" ), tr( "Restore Failed." ) + "\n" |
491 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) | 531 | + errorMsg, QString( tr( "Ok") ), QString( tr( "Details" ) ) ) ) |
492 | { | 532 | { |
493 | case 1: | 533 | case 1: |
494 | owarn << "Details pressed !" << oendl; | 534 | owarn << "Details pressed !" << oendl; |
495 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); | 535 | ErrorDialog* pErrDialog = new ErrorDialog( this, NULL, true ); |
496 | QFile errorFile( tempFileName ); | 536 | QFile errorFile( tempFileName ); |
497 | if ( errorFile.open(IO_ReadOnly) ) | 537 | if ( errorFile.open(IO_ReadOnly) ) |
498 | { | 538 | { |
499 | QTextStream t( &errorFile ); | 539 | QTextStream t( &errorFile ); |
500 | QString s; | 540 | QString s; |
501 | while ( !t.eof() ) | 541 | while ( !t.eof() ) |
502 | { // until end of file... | 542 | { // until end of file... |
503 | s += t.readLine(); // line of text excluding '\n' | 543 | s += t.readLine(); // line of text excluding '\n' |
504 | } | 544 | } |
505 | errorFile.close(); | 545 | errorFile.close(); |
506 | 546 | ||
507 | pErrDialog->m_textarea->setText( s ); | 547 | pErrDialog->m_textarea->setText( s ); |
508 | } | 548 | } |
509 | else | 549 | else |