44
44
The features that make Bazaar a good distributed version control system also
45
45
make it a good choice for backing itself up. In particular, complete and
46
46
consistent copies of any branch can easily be obtained with the ``branch`` and
47
``pull`` commands. As a result, a backup process can simply run ``bzr pull``
47
``pull`` commands. As a result, a backup process can simply run ``brz pull``
48
48
on a copy of the main branch to fully update that copy. If this backup
49
49
process runs periodically, then the backups will be as current as the last
50
50
time that ``pull`` was run. (This is in addition to the fact
60
$ bzr branch bzr+ssh://server.example.com/srv/bzr/trunk
61
$ bzr branch bzr+ssh://server.example.com/srv/bzr/feature-gui
60
$ brz branch bzr+ssh://server.example.com/srv/bzr/trunk
61
$ brz branch bzr+ssh://server.example.com/srv/bzr/feature-gui
63
63
to create the branches on the backup server. Then, we could regularly (for
64
64
example from ``cron``) do
68
68
$ cd /var/backup/trunk
69
$ bzr pull # the location to pull from is remembered
69
$ brz pull # the location to pull from is remembered
70
70
$ cd ../var/backup/feature-gui
71
$ bzr pull # again, the parent location is remembered
71
$ brz pull # again, the parent location is remembered
73
73
The action of pulling from the parent for all branches in some directory is
74
common enough that there is a plugin to do it. The `bzrtools`_ plugin
75
contains a ``multi-pull`` command that does a ``pull`` in all branches under a
78
.. _bzrtools: http://launchpad.net/bzrtools
80
With this plugin installed, the above periodically run commands would be
87
Note that ``multi-pull`` does a pull in *every* branch in the specified
88
directory (the current directory by default) and care should be taken that
89
this is the desired effect. A simple script could also substitute for the
90
multi-pull command while also offering greater flexibility.
74
common enough that there is a plugin to do it.
92
76
Bound Branch Backups
93
77
~~~~~~~~~~~~~~~~~~~~
95
When ``bzr pull`` is run regularly to keep a backup copy up to date, then it
79
When ``brz pull`` is run regularly to keep a backup copy up to date, then it
96
80
is possible that there are new revisions in the original branch that have not
97
81
yet been pulled into the backup branch. To alleviate this problem, we can set
98
82
the branches up so that new revisions are *pushed* to the backup rather than
102
86
is set up on the server itself rather than on the backup machine. For each
103
87
branch that should be backed up, you just need to use the ``bind`` command to
104
88
set the URL for the backup branch. In our example, we first need to create
105
the branches on the backup server (we'll use ``bzr push``, but we could as
106
easily have used ``bzr branch`` from the backup server)
89
the branches on the backup server (we'll use ``brz push``, but we could as
90
easily have used ``brz branch`` from the backup server)
110
94
$ cd /srv/bzr/projectx/trunk
111
$ bzr push bzr+ssh://backup.example.com/var/backup/trunk
95
$ brz push bzr+ssh://backup.example.com/var/backup/trunk
112
96
$ cd ../feature-gui
113
$ bzr push bzr+ssh://backup.example.com/var/backup/feature-gui
97
$ brz push bzr+ssh://backup.example.com/var/backup/feature-gui
115
99
and then we need to bind the main branches to their backups
120
$ bzr bind bzr+ssh://backup.example.com/var/backup/trunk
104
$ brz bind bzr+ssh://backup.example.com/var/backup/trunk
121
105
$ cd ../feature-gui
122
$ bzr bind bzr+ssh://backup.example.com/var/backup/feature-gui
106
$ brz bind bzr+ssh://backup.example.com/var/backup/feature-gui
124
108
A branch can only be bound to a single location, so multiple backups cannot
125
109
be created using this method.
159
143
but when it came time to restore from backups, finding out that the backups
160
144
themselves were flawed. As such, it is important to check the quality of the
161
145
backups periodically. In Bazaar, there are two ways to do this: using the
162
``bzr check`` command and by simply making a new branch from the backup. The
163
``bzr check`` command goes through all of the revisions in a branch and checks
146
``brz check`` command and by simply making a new branch from the backup. The
147
``brz check`` command goes through all of the revisions in a branch and checks
164
148
them for validity according to Bazaar's internal invariants. Since it goes
165
149
through every revision, it can be quite slow for large branches. The other
166
150
way to ensure that the backups can be restored from is to perform a test
167
151
restoration. This means performing the restoration process in a temporary
168
directory. After the restoration process, ``bzr check`` may again be relevant
152
directory. After the restoration process, ``brz check`` may again be relevant
169
153
for testing the validity of the restored branches. The following two sections
170
154
present two restoration recipes.
200
$ bzr branch bzr+ssh://backup.example.com/var/backup/trunk
201
$ bzr branch bzr+ssh://backup.example.com/var/backup/feature-gui
184
$ brz branch bzr+ssh://backup.example.com/var/backup/trunk
185
$ brz branch bzr+ssh://backup.example.com/var/backup/feature-gui
203
187
If there are multiple backups, then change the URL above to restore from the