| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | protected boolean run() { |
| 39 | final String name = args[0]; |
| 40 | if(!(name.isEmpty() || Databases.validName(name))) return error(NAME_INVALID_X, name); |
| 41 | |
| 42 | // find backup with or without date suffix |
| 43 | final StringList backups = context.databases.backups(name); |
| 44 | if(backups.isEmpty()) return error(BACKUP_NOT_FOUND_X, name); |
| 45 | |
| 46 | final String backup = backups.get(0), db = Databases.name(backup); |
| 47 | if(!db.isEmpty()) { |
| 48 | // close database if it's currently opened and not opened by others |
| 49 | if(!closed) closed = close(context, db); |
| 50 | // check if database is still pinned |
| 51 | if(context.pinned(db)) return error(DB_PINNED_X, db); |
| 52 | } |
| 53 | |
| 54 | // try to restore database |
| 55 | try { |
| 56 | restore(db, backup, soptions, this); |
| 57 | return db.isEmpty() || !closed || new Open(db).run(context) ? |
| 58 | info(DB_RESTORED_X, backup, jc().performance) : error(DB_NOT_RESTORED_X, db); |
| 59 | } catch(final IOException ex) { |
| 60 | Util.debug(ex); |
| 61 | return error(DB_NOT_RESTORED_X, db); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Restores the specified database . |