2. How to... : Set Up Gerrit Garbage Collection
   
Set Up Gerrit Garbage Collection
Gerrit Code Review garbage collection (gerrit gc) is a command that converts loose objects to packed, and that also removes unused objects. Micro Focus recommends that you run garbage collection on a regular basis to avoid performance problems associated with loose objects that occur over time.
This topic provides general examples of cron jobs you can use to set up garbage collection for your site. Note that syntax and supported features for cron jobs can vary across platforms. For more information, refer to cron and crontab documentation for your platform.
Tip: Consider running garbage collection on all of your projects on a regular basis. Choose a "quiet" time that will be unlikely to interfere with repository users.
Gerrit gc Syntax
The basic syntax for the Gerrit garbage collection command is:
ssh -p <port> <user>@<host> gerrit gc [--all] [ <project> ... ]
where:
<port> is the GitCentric port number, typically 29418.
<user> is a user with Gerrit "Administrate Server" privileges.
<host> is the name of the GitCentric host machine.
--all runs garbage collection on all projects in the repository.
<project> is the name of one or more individual projects in which you want to run garbage collection.
cron job Examples
You use cron jobs to execute commands, like gerrit gc, on a scheduled basis. The cron job format is a sequence of five fields used to specify day, time, and frequency; the sixth is used to specify the command:
Table 6. Cron Job Format
Field
Description
Allowed Values
MIN
Minute of the hour
0 to 59, *
HOUR
Hour of the day
0 to 23, *
DOM
Day of the month
1 to 31, *
MON
Month
1 to 12, *
DOW
Day of the week
0 to 6; *; sun, mon, tue, wed, thu, fri, sat
CMD
Command
The command to be executed
The following examples show how you can use cron jobs to run garbage collection on your Gerrit projects. In these examples, "comet" is the name of the GitCentric host machine.
Run garbage collection on all projects at midnight every day of the week.
0 0 * * * ssh -p 29418 admin@comet gerrit gc --all
Tip: You can use the keyword @daily to express 0 0 * * *.
Run garbage collection on all projects weekly at midnight Sunday.
0 0 * * sun -p 29418 admin@comet gerrit gc --all
Tip: You can use the keyword @weekly to express 0 0 * * 0 (which is the equivalent
of 0 0 * * sun).
Run garbage collection on "acme" and "phoenix" projects Monday through Friday at 1:30 a.m.
0 0 * * 1-5 ssh -p 29418 admin@comet gerrit gc acme phoenix