-rw-r--r-- | noncore/settings/backup/backuprestore.cpp | 51 | ||||
-rw-r--r-- | share/backup/device_table-minimal.txt | 20 |
2 files changed, 55 insertions, 16 deletions
diff --git a/noncore/settings/backup/backuprestore.cpp b/noncore/settings/backup/backuprestore.cpp index 869c1b8..d028379 100644 --- a/noncore/settings/backup/backuprestore.cpp +++ b/noncore/settings/backup/backuprestore.cpp | |||
@@ -235,181 +235,200 @@ void BackupAndRestore::selectItem(QListViewItem *currentItem) | |||
235 | if(currentItem->text(HEADER_BACKUP) == "B") | 235 | if(currentItem->text(HEADER_BACKUP) == "B") |
236 | { | 236 | { |
237 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); | 237 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/null")); |
238 | currentItem->setText(HEADER_BACKUP, ""); | 238 | currentItem->setText(HEADER_BACKUP, ""); |
239 | } | 239 | } |
240 | else | 240 | else |
241 | { | 241 | { |
242 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); | 242 | currentItem->setPixmap(HEADER_NAME, Resource::loadPixmap("backup/check")); |
243 | currentItem->setText(HEADER_BACKUP, "B"); | 243 | currentItem->setText(HEADER_BACKUP, "B"); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | void BackupAndRestore::scanForApplicationSettings() | 247 | void BackupAndRestore::scanForApplicationSettings() |
248 | { | 248 | { |
249 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); | 249 | QDir d( QDir::homeDirPath() + "/" + QString( applicationSettings->text(BACKUP_LOCATION) ) ); |
250 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); | 250 | d.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks ); |
251 | const QFileInfoList *list = d.entryInfoList(); | 251 | const QFileInfoList *list = d.entryInfoList(); |
252 | QFileInfoListIterator it( *list ); | 252 | QFileInfoListIterator it( *list ); |
253 | QFileInfo *fi; | 253 | QFileInfo *fi; |
254 | while ( (fi=it.current()) ) | 254 | while ( (fi=it.current()) ) |
255 | { | 255 | { |
256 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; | 256 | //odebug << (d.path()+"/"+fi->fileName()).latin1() << oendl; |
257 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) | 257 | if ( ( fi->fileName() != "." ) && ( fi->fileName() != ".." ) ) |
258 | { | 258 | { |
259 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); | 259 | QListViewItem *newItem = new QListViewItem(applicationSettings, fi->fileName()); |
260 | selectItem(newItem); | 260 | selectItem(newItem); |
261 | } | 261 | } |
262 | ++it; | 262 | ++it; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * The "Backup" button has been pressed. Get a list of all of the files that | 267 | * The "Backup" button has been pressed. Get a list of all of the files that |
268 | * should be backed up. If there are no files, emit and error and exit. | 268 | * should be backed up. If there are no files, emit and error and exit. |
269 | * Determine the file name to store the backup in. Backup the file(s) using | 269 | * Determine the file name to store the backup in. Backup the file(s) using |
270 | * tar and gzip --best. Report failure or success | 270 | * tar and gzip --best. Report failure or success |
271 | */ | 271 | */ |
272 | void BackupAndRestore::backup() | 272 | void BackupAndRestore::backup() |
273 | { | 273 | { |
274 | if ( cb_type_userdata->isChecked() ) | 274 | if ( cb_type_userdata->isChecked() ) |
275 | backupUserData(); | 275 | backupUserData(); |
276 | else | 276 | else |
277 | backupRootFs(); | 277 | backupRootFs(); |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
281 | void BackupAndRestore::backupRootFs() | 281 | void BackupAndRestore::backupRootFs() |
282 | { | 282 | { |
283 | //#define MDEBUG | 283 | if ( ( ODevice::inst()->model() != Model_Zaurus_SL5000 ) && ( ODevice::inst()->model() != Model_Zaurus_SL5500 ) ) |
284 | #ifndef MDEBUG | 284 | { |
285 | QMessageBox::critical( this, "Opie-Backup", "<qt>This feature is not yet implemented.</qt>", "Bummer!" ); | 285 | QMessageBox::critical( this, "Not yet implemented!", "<qt>Sorry, support for this model is not yet done.</qt>", "Ok" ); |
286 | return; | 286 | return; |
287 | #endif | 287 | } |
288 | |||
289 | if ( !QFile::exists( "/usr/bin/mkfs.jffs2" ) && !QFile::exists( "/usr/sbin/mkfs.jffs2" ) ) | ||
290 | { | ||
291 | QMessageBox::critical( this, "Can't find utility!", "<qt>Can't find mkfs.jffs2 - Install mtd-utils.</qt>", "Ok" ); | ||
292 | return; | ||
293 | } | ||
294 | |||
288 | // call 'mount' and parse its output to gather the device on which the root partition is mounted | 295 | // call 'mount' and parse its output to gather the device on which the root partition is mounted |
289 | FILE* mountp = popen( "mount", "r" ); | 296 | FILE* mountp = popen( "mount", "r" ); |
290 | QString device; | 297 | QString device; |
291 | QString mountpoint; | 298 | QString mountpoint; |
292 | { | 299 | { |
293 | QTextStream mounto( mountp, IO_ReadOnly ); | 300 | QTextStream mounto( mountp, IO_ReadOnly ); |
294 | QString on; | 301 | QString on; |
295 | QString type; | 302 | QString type; |
296 | QString filesystem; | 303 | QString filesystem; |
297 | QString options; | 304 | QString options; |
298 | while ( !mounto.atEnd() ) | 305 | while ( !mounto.atEnd() ) |
299 | { | 306 | { |
300 | mounto >> device >> on >> mountpoint >> type >> filesystem >> options; | 307 | mounto >> device >> on >> mountpoint >> type >> filesystem >> options; |
301 | if ( mountpoint == "/" ) break; | 308 | if ( mountpoint == "/" ) break; |
302 | } | 309 | } |
303 | odebug << device << " is formatted w/ " << filesystem << " and mounted on " << mountpoint << oendl; | 310 | odebug << device << " is formatted w/ '" << filesystem << "' and mounted on '" << mountpoint << "'" << oendl; |
304 | 311 | ||
305 | if ( !mountpoint.startsWith( "/dev/mtdblock" ) ) | 312 | if ( !device.startsWith( "/dev/mtdblock" ) ) |
306 | { | 313 | { |
307 | QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported rootfs %1 - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" ); | 314 | QMessageBox::critical( this, "Can't backup!", QString( "<qt>unsupported root device '%1' - needs to be /dev/mtdblockN</qt>").arg( device ), "Ok" ); |
308 | #ifndef MDEBUG | ||
309 | return; | 315 | return; |
310 | #endif | ||
311 | } | 316 | } |
312 | } // at this point, the QTextStream has been destroy and we can close the FILE* | 317 | } // at this point, the QTextStream has been destroy and we can close the FILE* |
313 | pclose( mountp ); | 318 | pclose( mountp ); |
314 | 319 | ||
315 | #ifndef MDEBUG | 320 | #if 1 |
316 | int rootmtd = device.right( 1 ).toInt(); | 321 | int rootmtd = device.right( 1 ).toInt(); |
317 | #else | 322 | #else |
318 | int rootmtd = 0; | 323 | int rootmtd = 0; |
319 | #endif | 324 | #endif |
320 | odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl; | 325 | odebug << "root mtdblock seems to be '" << rootmtd << "'" << oendl; |
321 | 326 | ||
322 | // scan /proc/mtd to gather the size and erasesize of the root mtdblock | 327 | // scan /proc/mtd to gather the size and erasesize of the root mtdblock |
323 | QFile procmtdf( "/proc/mtd" ); | 328 | QFile procmtdf( "/proc/mtd" ); |
324 | if ( !procmtdf.open( IO_ReadOnly ) ) | 329 | if ( !procmtdf.open( IO_ReadOnly ) ) |
325 | { | 330 | { |
326 | QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" ); | 331 | QMessageBox::critical( this, "Can't backup!", "<qt>Can't open /proc/mtd</qt>", "Ok" ); |
332 | return; | ||
327 | } | 333 | } |
328 | 334 | ||
329 | QTextStream procmtd( &procmtdf ); | 335 | QTextStream procmtd( &procmtdf ); |
330 | for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things | 336 | for ( int i = 0; i <= rootmtd; ++i ) procmtd.readLine(); // skip uninteresting things |
331 | QString dev; | 337 | QString dev; |
332 | QString size; | 338 | QString size; |
333 | QString erasesize; | 339 | QString erasesize; |
334 | QString devname; | 340 | QString devname; |
335 | procmtd >> dev >> size >> erasesize >> devname; | 341 | procmtd >> dev >> size >> erasesize >> devname; |
336 | 342 | ||
337 | odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl; | 343 | odebug << "device " << dev << " size = " << size << ", erase size = " << erasesize << ", name = " << devname << "\"" << oendl; |
338 | 344 | ||
339 | // compute pad | 345 | // compute pad |
340 | QString pad = "--pad"; | 346 | QString pad = "--pad"; |
341 | switch ( ODevice::inst()->model() ) | 347 | switch ( ODevice::inst()->model() ) |
342 | { | 348 | { |
343 | case Model_Zaurus_SL5000: pad = "--pad=14680064"; break; | 349 | case Model_Zaurus_SL5000: pad = "--pad=14680064"; break; |
344 | case Model_Zaurus_SL5500: pad = "--pad=14680064"; break; | 350 | case Model_Zaurus_SL5500: pad = "--pad=14680064"; break; |
345 | // FIXME: Add Beagle and SIMpad | 351 | // FIXME: Add Beagle and SIMpad |
346 | } | 352 | } |
347 | 353 | ||
348 | // compute eraseblock | 354 | // compute eraseblock |
349 | QString eraseblock = "--eraseblock=0x" + erasesize; | 355 | QString eraseblock = "--eraseblock=0x" + erasesize; |
350 | 356 | ||
351 | // compute output | 357 | // compute output |
352 | QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()]; | 358 | QString outputFile = "--output=" + backupLocations[storeToLocation->currentText()]; |
353 | QDateTime datetime = QDateTime::currentDateTime(); | 359 | QDateTime datetime = QDateTime::currentDateTime(); |
354 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 360 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
355 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 361 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
356 | outputFile += "/initrd.bin-" + dateString; | 362 | outputFile += "/initrd.bin-" + dateString; |
357 | 363 | ||
358 | // call mkfs.jffs2 to create the backup | 364 | // call mkfs.jffs2 to create the backup |
359 | QString cmdline = QString( "mkfs.jffs2 --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock ); | 365 | QString cmdline = QString( "mkfs.jffs2 --faketime --root=/ %1 --little-endian %2 %3 -n" ).arg( outputFile ).arg( pad ).arg( eraseblock ); |
366 | cmdline.append( " --ignore=/tmp --ignore=/mnt --ignore=/var --ignore=/proc" ); | ||
360 | owarn << "Calling '" << cmdline << "'" << oendl; | 367 | owarn << "Calling '" << cmdline << "'" << oendl; |
361 | 368 | ||
362 | #ifndef MDEBUG | 369 | OWait *owait = new OWait(); |
363 | ::system( cmdline ); | 370 | Global::statusMessage( tr( "Backing up..." ) ); |
364 | #endif | 371 | owait->show(); |
372 | qApp->processEvents(); | ||
365 | 373 | ||
366 | // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad | 374 | int r = ::system( cmdline ); |
375 | |||
376 | owait->hide(); | ||
377 | delete owait; | ||
378 | |||
379 | if ( r != 0 ) | ||
380 | { | ||
381 | perror("Error: "); | ||
382 | QString errorMsg = QString( tr( "<qt>%1</qt>" ).arg( strerror( errno ) ) ); | ||
383 | QMessageBox::critical(this, tr( "Backup Failed!" ), errorMsg, QString( tr( "Ok" ) ) ); | ||
384 | } | ||
367 | 385 | ||
386 | // FIXME: Add image postprocessing for C7x0 and C8x0, for Beagle, for SIMpad | ||
368 | } | 387 | } |
369 | 388 | ||
370 | void BackupAndRestore::backupUserData() | 389 | void BackupAndRestore::backupUserData() |
371 | { | 390 | { |
372 | QString backupFiles; | 391 | QString backupFiles; |
373 | if(getBackupFiles(backupFiles, NULL) == 0) | 392 | if(getBackupFiles(backupFiles, NULL) == 0) |
374 | { | 393 | { |
375 | QMessageBox::critical(this, "Message", | 394 | QMessageBox::critical(this, "Message", |
376 | "No items selected.",QString("Ok") ); | 395 | "No items selected.",QString("Ok") ); |
377 | return; | 396 | return; |
378 | } | 397 | } |
379 | 398 | ||
380 | OWait *owait = new OWait(); | 399 | OWait *owait = new OWait(); |
381 | Global::statusMessage( tr( "Backing up..." ) ); | 400 | Global::statusMessage( tr( "Backing up..." ) ); |
382 | owait->show(); | 401 | owait->show(); |
383 | qApp->processEvents(); | 402 | qApp->processEvents(); |
384 | 403 | ||
385 | QString outputFile = backupLocations[storeToLocation->currentText()]; | 404 | QString outputFile = backupLocations[storeToLocation->currentText()]; |
386 | 405 | ||
387 | QDateTime datetime = QDateTime::currentDateTime(); | 406 | QDateTime datetime = QDateTime::currentDateTime(); |
388 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + | 407 | QString dateString = QString::number( datetime.date().year() ) + QString::number( datetime.date().month() ).rightJustify(2, '0') + |
389 | QString::number( datetime.date().day() ).rightJustify(2, '0'); | 408 | QString::number( datetime.date().day() ).rightJustify(2, '0'); |
390 | 409 | ||
391 | outputFile += "/" + dateString; | 410 | outputFile += "/" + dateString; |
392 | 411 | ||
393 | QString t = outputFile; | 412 | QString t = outputFile; |
394 | int c = 1; | 413 | int c = 1; |
395 | while(QFile::exists(outputFile + EXTENSION)) | 414 | while(QFile::exists(outputFile + EXTENSION)) |
396 | { | 415 | { |
397 | outputFile = t + QString("%1").arg(c); | 416 | outputFile = t + QString("%1").arg(c); |
398 | c++; | 417 | c++; |
399 | } | 418 | } |
400 | 419 | ||
401 | // We execute tar and compressing its output with gzip.. | 420 | // We execute tar and compressing its output with gzip.. |
402 | // The error output will be written into a temp-file which could be provided | 421 | // The error output will be written into a temp-file which could be provided |
403 | // for debugging.. | 422 | // for debugging.. |
404 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; | 423 | odebug << "Storing file: " << outputFile.latin1() << "" << oendl; |
405 | outputFile += EXTENSION; | 424 | outputFile += EXTENSION; |
406 | 425 | ||
407 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) | 426 | QString commandLine = QString( "cd %1 && (tar -X %1 -cz %2 Applications/backup/exclude -f %3 ) 2> %4" ).arg( QDir::homeDirPath() ) |
408 | .arg( getExcludeFile() ) | 427 | .arg( getExcludeFile() ) |
409 | .arg( backupFiles ) | 428 | .arg( backupFiles ) |
410 | .arg( outputFile.latin1() ) | 429 | .arg( outputFile.latin1() ) |
411 | .arg( tempFileName.latin1() ); | 430 | .arg( tempFileName.latin1() ); |
412 | 431 | ||
413 | odebug << commandLine << oendl; | 432 | odebug << commandLine << oendl; |
414 | 433 | ||
415 | int r = system( commandLine ); | 434 | int r = system( commandLine ); |
diff --git a/share/backup/device_table-minimal.txt b/share/backup/device_table-minimal.txt new file mode 100644 index 0000000..66cafae --- a/dev/null +++ b/share/backup/device_table-minimal.txt | |||
@@ -0,0 +1,20 @@ | |||
1 | /dev/initctl p 600 0 0 - - -- | ||
2 | /dev/apm_bios c 660 0 46 10 134 - -- | ||
3 | /dev/fb0 c 600 0 0 29 0 - -- | ||
4 | /dev/hda b 660 0 6 3 0 - -- | ||
5 | /dev/hda b 660 0 6 3 1 1 120 | ||
6 | /dev/kmem c 640 0 15 1 2 - -- | ||
7 | /dev/mem c 640 0 15 1 1 - -- | ||
8 | /dev/null c 666 0 0 1 3 - -- | ||
9 | /dev/ram b 640 0 0 1 0 0 14 | ||
10 | /dev/tty c 662 0 5 5 0 - -- | ||
11 | /dev/tty c 666 0 5 4 0 0 19 | ||
12 | /dev/ttyS c 640 0 5 4 64 0 11 | ||
13 | /dev/ttySA c 640 0 5 204 5 0 11 | ||
14 | /dev/zero c 644 0 0 1 5 -- | ||
15 | /dev/mtd c 660 0 6 90 0 0 28 | ||
16 | /dev/mtdblock b 640 0 0 31 0 0 18 | ||
17 | /dev/console c 662 0 5 5 1 -- | ||
18 | /bin/tinylogin f 4755 0 0 - - -- | ||
19 | /bin/mount f 4755 0 0 - - -- | ||
20 | /bin/umount f 4755 0 0 - - -- | ||