Ticket #2304: trac_pg_backup.3.patch
| File trac_pg_backup.3.patch, 3.6 KB (added by Shane Caraveo <shanec@…>, 3 years ago) |
|---|
-
vendor/trac/trac/env.py
33 33 from trac.versioncontrol import RepositoryManager 34 34 from trac.web.href import Href 35 35 36 __all__ = ['Environment', 'IEnvironmentSetupParticipant', 'open_environment'] 36 __all__ = ['Environment', 'IEnvironmentSetupParticipant', 'open_environment', 37 'IBackupProvider'] 37 38 38 39 39 40 class IEnvironmentSetupParticipant(Interface): … … 59 60 performed the upgrades they need without an error being raised. 60 61 """ 61 62 63 class IBackupProvider(Interface): 64 """Extension point interface for components that implment support for 65 backup of database tables during environment upgrade.""" 62 66 67 def supports_database(env): 68 """Returns a boolean if this provider supports the database 69 used by the environment. The provider should check the 70 trac.database configuration.""" 71 72 def backup(env, dest): 73 """Called when a new Trac environment is created.""" 74 63 75 class Environment(Component, ComponentManager): 64 76 """Trac stores project information in a Trac environment. 65 77 … … 71 83 * wiki and ticket attachments. 72 84 """ 73 85 setup_participants = ExtensionPoint(IEnvironmentSetupParticipant) 86 backup_providers = ExtensionPoint(IBackupProvider) 74 87 75 88 shared_plugins_dir = PathOption('inherit', 'plugins_dir', '', 76 89 """Path of the directory containing additional plugins. … … 399 412 yield username, name, email 400 413 401 414 def backup(self, dest=None): 402 """ Simple SQLite-specific backup of the database.415 """Backup the databas using database specific backup providers. 403 416 404 417 @param dest: Destination file; if not specified, the backup is stored in 405 418 a file called db_name.trac_version.bak 406 419 """ 407 import shutil 420 for provider in self.backup_providers: 421 if provider.supports_database(self): 422 provider.backup(self, dest) 423 return 424 raise TracError(_('No IBackupProvider supports this database type.')) 408 425 409 db_str = self.config.get('trac', 'database')410 if not db_str.startswith('sqlite:'):411 raise TracError(_('Can only backup sqlite databases'))412 db_name = os.path.join(self.path, db_str[7:])413 if not dest:414 dest = '%s.%i.bak' % (db_name, self.get_version())415 shutil.copy (db_name, dest)416 417 426 def needs_upgrade(self): 418 427 """Return whether the environment needs to be upgraded.""" 419 428 db = self.get_db_cnx() … … 471 480 return self._abs_href 472 481 abs_href = property(_get_abs_href, 'The application URL') 473 482 483 class DefaultBackupProvider(Component): 484 implements(IBackupProvider) 474 485 486 def supports_database(self, env): 487 db_str = env.config.get('trac', 'database') 488 return db_str.startswith('sqlite:') 489 490 def backup(self, env, dest=None): 491 """Simple SQLite-specific backup of the database. 492 493 @param dest: Destination file; if not specified, the backup is stored in 494 a file called db_name.trac_version.bak 495 """ 496 import shutil 497 db_str = env.config.get('trac', 'database') 498 db_name = os.path.join(env.path, db_str[7:]) 499 if not dest: 500 dest = '%s.%i.bak' % (db_name, env.get_version()) 501 shutil.copy (db_name, dest) 502 475 503 class EnvironmentSetup(Component): 476 504 implements(IEnvironmentSetupParticipant) 477 505
