B. Backup and Restore
   
B. Backup and Restore
This appendix describes the commands and processes you can use to back up and restore GitCentric.
Commands for Backup and Restore
GitCentric provides two sets of commands for backing up and restoring GitCentric, summarized in the following table:
Table 1. Summary of Backup and Restore Commands
Command
Description
When to Use
full_backup.sh
full_restore.sh
The full_backup.sh command backs up the GitCentric databases, your Git repositories, and your configuration files. Likewise, full_restore.sh copies all required files to the new location.
Use full_backup.sh and full_restore.sh any time you wish to completely back up GitCentric. You should also use these commands when migrating GitCentric from one server to another.
backupdbs
restoredbs
The low-level backupdbs and restoredbs commands, as the names imply, back up and restore only the GitCentric databases. Other important data, like your Git repositories and configuration files are not backed up by the backupdbs command.
backupdbs and restoredbs are kandoMaintain commands. See Appendix A: The kandoMaintain Utility for more information.
You might wish to use these commands if your current backup strategy includes a third-party tool for backing up your repositories.
 
Note: If you are currently using backupdbs and restoredbs to back up GitCentric, you can continue to do so.
Micro Focus recommends that you use the full_backup.sh and full_restore.sh commands to back up and restore GitCentric as described in the remainder of this appendix.
Best Practices
Micro Focus recommends that you back up GitCentric on a daily basis -- every night, for example. You can back up GitCentric at any time, but Micro Focus recommends that you choose a time of light system usage.
Tip: Consider creating a cron job for GitCentric backups. For examples of cron jobs, see Set Up Gerrit Garbage Collection on page 55.
Backing Up GitCentric
This section describes the background information and procedures you use to back up GitCentric.
What Gets Backed Up?
The full_backup.sh command backs up:
all Git repositories
all GitCentric databases
all configuration settings -- database connection, Gerrit configuration (site/etc), Gerrit hooks (site/hooks), SSH keys used for replication (site/ssh)
All files are backed up to a .tar file that is created at the location from which you run the full_backup.sh command. The file is named kando_backup_site_etc_<yyyymmdd>.tar, where <yyyymmdd> is the year, month, and day.
You can move the backup file to -- and restore it from -- a different location if you choose.
What are the GitCentric Databases?
The GitCentric databases, "kando" and "gcreviewdb", are PostgreSQL databases installed on the GitCentric server. These databases contain all AccuRev stream-Git branch mappings, as well as a history of all import and export activity. Stream-branch mappings are recorded using AccuRev transaction-Git commit pairs. For more information on the GitCentric databases, see Basic Architecture on page 3.
Note: The GitCentric databases are entirely separate from the AccuRev database; the procedures described in this appendix apply only to the GitCentric databases; they have no effect on the AccuRev database.
How to Back Up GitCentric
1. Stop the GitCentric server using shutdown.sh:
<ac_home>/WebUI/tomcat/bin/shutdown.sh
2. Run full_backup.sh -l <path to gc_home>
where
<path to gc_home> is the full path to the GitCentric home directory you want to back up.

For example:

./full_backup.sh -l /home/gitcentric/AccuRevGitCentric
GitCentric displays a completion message, including the name of the .tar file, if the backup was successful; otherwise, it displays errors.
3. Start the GitCentric server using startup.sh:
<ac_home>/WebUI/tomcat/bin/startup.sh
Note: Make sure that the user starting Tomcat has write access to the logs, temp, webapps, and work directories in <ac_home>/WebUI/tomcat. This user should have read access to all other Tomcat directories and files.
Restoring GitCentric
This section describes the background information and procedure you use to restore GitCentric.
Caution: Restore Overwrites Existing GitCentric Installations
The full_restore.sh command completely overwrites an existing GitCentric installation. If you are restoring to an existing GitCentric installation, make sure there is no data under the GitCentric home directory that needs to be saved.
Prerequisites
In order to successfully run the full_restore.sh command:
you must have an existing GitCentric installation to use as the target for the restore operation. This GitCentric installation can be empty.
<ac_home>/jre/bin must be in your system’s search path (set using the $PATH environment variable)
<ac_home>/postgresql/bin must be in your system’s search path (set using the $PATH environment variable)
What Gets Restored?
The full_restore.sh command restores all the files and databases in the kando_backup_site_etc_<yyyymmdd>.tar created by the full_backup.sh command. See What Gets Backed Up? on page 84 for more information.
How to Restore GitCentric
To restore GitCentric:
1. Stop the GitCentric server using shutdown.sh:
<ac_home>/WebUI/tomcat/bin/shutdown.sh
2. Run full_restore.sh -l <path to gc_home> <backup.tar file>
where
<path to gc_home> is the full path to the GitCentric home directory to which you want to restore
<backup.tar file> is the name of the .tar file created by full_backup.sh.

For example:

./full_restore.sh -l /home/gitcentric/AccuRevGitCentric kando_backup_site_etc_<20150213>.tar
3. Important: Review the full_restore.sh output and perform any required actions. See Restore Scenarios on page 87 for more information on restore situations you may encounter.
4. Restart Tomcat:
<ac_home>/WebUI/tomcat/bin/startup.sh
Note: Make sure that the user starting Tomcat has write access to the logs, temp, webapps, and work directories in <ac_home>/WebUI/tomcat. This user should have read access to all other Tomcat directories and files.
Next Steps
If your GitCentric restore was successful, you might need to perform one or more of the following tasks depending on whether or not you restored GitCentric to a new location or to a new machine. In addition, you might need to merge Gerrit configuration files.
If You Restored to a New Location
If you restored GitCentric to a new location on the existing machine, you need to:
1. Modify docBase in <ac_home>/WebUI/tomcat/conf/Catalina/<hostname>/gitcentric.xml and kandoBridge.xml to point to the new GitCentric location.
2. Compare Gerrit configuration files in kando_backup_site_etc_<yyyymmdd>.tar and merge any changes required to support your GitCentric installation to the new ../site/etc.
3. Restart Tomcat:
<ac_home>/WebUI/tomcat/bin/shutdown.sh
<ac_home>/WebUI/tomcat/bin/startup.sh
If You Restored to a New Machine
If you restored GitCentric to a new machine, as you might in a migration scenario, for example, you need to:
1. Set up Tomcat on the new machine with:
<ac_home>/WebUI/tomcat/conf/Catalina/<hostname>/gitcentric.xml
and
<ac_home>/WebUI/tomcat/conf/Catalina/<hostname>/kandoBridge.xml
2. Compare Gerrit configuration files in kando_backup_site_etc_<yyyymmdd>.tar and merge any changes required to support your GitCentric installation to the new ../site/etc.
3. Restart Tomcat to adjust AccuRev settings:
<ac_home>/WebUI/tomcat/bin/shutdown.sh
<ac_home>/WebUI/tomcat/bin/startup.sh
4. Use PostgreSQL psql or pgadmin tools to edit the Kando database "acserver" table to correct the server client path for each AccuRev server.
If You Restored to the Same Location
If you restored to the same location, simply unpack the kando_backup_site_etc_<yyyymmdd>.tar file by running:
tar xvf kando_backup_site_etc_<yyyymmdd>.tar
Restore Scenarios
In typical usage, GitCentric displays a message like the following for each Git branch that is successfully restored:
Processing branch refs/heads/master in repository /sandbox/llowry/tmp/ws/git/Repo2.git/
==============================
Branch is in sync with the GitCentric database.
When the restore is successful, no action is required on the part of the GitCentric administrator. The remainder of this section describes other scenarios that require the attention of the GitCentric administrator.
Overflow
An overflow condition occurs when the GitCentric database is backed up before the Git repositories are copied. In this event, it is possible that the GitCentric database and the Git repository copies are out of synch -- specifically, the GitCentric database probably does not have a complete set of AccuRev transaction-Git commit pairs reflecting the latest commits in the Git repositories.
When this happens, the GitCentric restore:
identifies the latest mapped Git commit of which it is aware and resets the head there.
creates a new branch that contains the commits that are not recorded in the GitCentric database. The new branch is named kando_backup_overflow_<name> where <name> is original branch name.
Writes a message to output like the following:
Processing branch refs/heads/maint in repository /sandbox/llowry/tmp/ws/git/Repo2.git/
==============================
Creating kando_backup_overflow_maint; review divergence with maint and merge as necessary.
In the case of an overflow condition, it is up to the GitCentric administrator to determine whether or not these changes need to be merged into the original branch and pushed to the Git repository. If the changes represented by the unrecorded commits are already in AccuRev, GitCentric will automatically export them to the restored repository after you start the GitCentric server. If the missing changes are not in AccuRev, the user can clone, then fast forward-only merge from the overflow branch to the named branch, and push.
Rollback
A rollback condition can occur when there is a large interval of time between when the copy of the Git repositories was created and the GitCentric database backup was performed. In this event, the GitCentric database will have recorded Git commits which are not in the restored repositories.
When the GitCentric restore encounters a rollback condition, it writes a message to output like the following:
Processing branch refs/heads/hotfix in repository /sandbox/llowry/tmp/ws/git/Repo1.git/
==============================
Rolling back mapped transactions that are higher than 61.
In this example, the GitCentric administrator needs to be aware that any AccuRev transaction-Git commit pair greater than transaction number 61 is not known to the Git repositories; GitCentric has rolled back database transactions to 61 -- the last value known to the Git repositories. Users that have any missing changes in their clone should push them again.
Missing Branch in the Repository Copy
If GitCentric restore cannot locate a branch, it writes a message to output like the following:
Processing branch refs/heads/spec in repository /sandbox/llowry/tmp/ws/git/Repo1.git/
==============================
Branch could not be found. Make sure the repository is at the expected location with the appropriate branch.
In this case, the GitCentric administrator needs to ensure that the copies of all Git repositories have been copied to their original location (that is, the location at the time the GitCentric database backup was created) and that all expected branches are present in those repositories. You may need to delete and recreate the branch mapping in GitCentric.