My favorites
▼
|
Sign in
svnbook
Version Control With Subversion
Project Home
Issues
Source
Checkout
|
Browse
|
Changes
|
‹r3305
r3707
Source path:
svn
/
tags
/
en-1.5-final
/
src
/
en
/
book
/
ch05-repository-admin.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
<chapter id="svn.reposadmin">
<title>Repository Administration</title>
<para>The Subversion repository is the central storehouse of all
your versioned data. As such, it becomes an obvious candidate for
all the love and attention an administrator can offer. While the
repository is generally a low-maintenance item, it is important to
understand how to properly configure and care for it so that
potential problems are avoided, and so actual problems are safely
resolved.</para>
<para>In this chapter, we'll discuss how to create and configure a
Subversion repository. We'll also talk about repository
maintenance, providing examples of how and when to use the
<command>svnlook</command> and <command>svnadmin</command> tools
provided with Subversion. We'll address some common questions and
mistakes and give some suggestions on how to arrange the data in
the repository.</para>
<para>If you plan to access a Subversion repository only in the
role of a user whose data is under version control (i.e., via
a Subversion client), you can skip this chapter altogether.
However, if you are, or wish to become, a Subversion repository
administrator,
<footnote>
<para>This may sound really prestigious and lofty, but we're
just talking about anyone who is interested in that
mysterious realm beyond the working copy where everyone's
data hangs out.</para>
</footnote>
this chapter is for you.</para>
<!-- ================================================================= -->
<!-- ================================================================= -->
<!-- ================================================================= -->
<sect1 id="svn.reposadmin.basics">
<title>The Subversion Repository, Defined</title>
<para>Before jumping into the broader topic of repository
administration, let's further define what a repository is. How
does it look? How does it feel? Does it take its tea hot or
iced, sweetened, and with lemon? As an administrator, you'll be
expected to understand the composition of a repository both from
a literal, OS-level perspective—how a repository looks and
acts with respect to non-Subversion tools—and from a
logical perspective—dealing with how data is represented
<emphasis>inside</emphasis> the repository.</para>
<para>Seen through the eyes of a typical file browser application
(such as Windows Explorer) or command-line based filesystem
navigation tools, the Subversion repository is just another
directory full of stuff. There are some subdirectories with
human-readable configuration files in them, some subdirectories
with some not-so-human-readable data files, and so on. As in
other areas of the Subversion design, modularity is given high
regard, and hierarchical organization is preferred to cluttered
chaos. So a shallow glance into a typical repository from a
nuts-and-bolts perspective is sufficient to reveal the basic
components of the repository:</para>
<screen>
$ ls repos
conf/ dav/ db/ format hooks/ locks/ README.txt
</screen>
<para>Here's a quick fly-by overview of what exactly you're seeing
in this directory listing. (Don't get bogged down in the
terminology—detailed coverage of these components exists
elsewhere in this and other chapters.)</para>
<variablelist>
<varlistentry>
<term>conf</term>
<listitem>
<para>A directory containing configuration files</para>
</listitem>
</varlistentry>
<varlistentry>
<term>dav</term>
<listitem>
<para>A directory provided to
<filename>mod_dav_svn</filename> for its private
housekeeping data</para>
</listitem>
</varlistentry>
<varlistentry>
<term>db</term>
<listitem>
<para>The data store for all of your versioned data</para>
</listitem>
</varlistentry>
<varlistentry>
<term>format</term>
<listitem>
<para>A file that contains a single integer that
indicates the version number of the repository layout</para>
</listitem>
</varlistentry>
<varlistentry>
<term>hooks</term>
<listitem>
<para>A directory full of hook script templates (and hook
scripts themselves, once you've installed some)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>locks</term>
<listitem>
<para>A directory for Subversion's repository lock
files, used for tracking accessors to the repository</para>
</listitem>
</varlistentry>
<varlistentry>
<term>README.txt</term>
<listitem>
<para>A file whose contents merely inform its readers that
they are looking at a Subversion repository</para>
</listitem>
</varlistentry>
</variablelist>
<para>Of course, when accessed via the Subversion libraries, this
otherwise unremarkable collection of files and directories
suddenly becomes an implementation of a virtual, versioned
filesystem, complete with customizable event triggers. This
filesystem has its own notions of directories and files, very
similar to the notions of such things held by real filesystems
(such as NTFS, FAT32, ext3, etc.). But this is a special
filesystem—it hangs these directories and files from
revisions, keeping all the changes you've ever made to them
safely stored and forever accessible. This is where the
entirety of your versioned data lives.</para>
</sect1>
<!-- ================================================================= -->
<!-- ================================================================= -->
<!-- ================================================================= -->
<sect1 id="svn.reposadmin.planning">
<title>Strategies for Repository Deployment</title>
<para>Due largely to the simplicity of the overall design of the
Subversion repository and the technologies on which it relies,
creating and configuring a repository are fairly straightforward
tasks. There are a few preliminary decisions you'll want to
make, but the actual work involved in any given setup of a
Subversion repository is pretty basic, tending toward
mindless repetition if you find yourself setting up multiples of
these things.</para>
<para>Some things you'll want to consider beforehand, though, are:</para>
<itemizedlist>
<listitem>
<para>What data do you expect to live in your repository (or
repositories), and how will that data be organized?</para>
</listitem>
<listitem>
<para>Where will your repository live, and how will it be
accessed?</para>
</listitem>
<listitem>
<para>What types of access control and repository event
reporting do you need?</para>
</listitem>
<listitem>
<para>Which of the available types of data store do you want
to use?</para>
</listitem>
</itemizedlist>
<para>In this section, we'll try to help you answer those
questions.</para>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.projects.chooselayout">
<title>Planning Your Repository Organization</title>
<para>While Subversion allows you to move around versioned files
and directories without any loss of information, and even
provides ways of moving whole sets of versioned history from
one repository to another, doing so can greatly disrupt the
workflow of those who access the repository often and come to
expect things to be at certain locations. So before creating
a new repository, try to peer into the future a bit; plan
ahead before placing your data under version control. By
conscientiously <quote>laying out</quote> your repository or
repositories and their versioned contents ahead of time, you
can prevent many future headaches.</para>
<para>Let's assume that as repository administrator, you will be
responsible for supporting the version control system for
several projects. Your first decision is whether to use a
single repository for multiple projects, or to give each
project its own repository, or some compromise of these
two.</para>
<para>There are benefits to using a single repository for
multiple projects, most obviously the lack of duplicated
maintenance. A single repository means that there is one set
of hook programs, one thing to routinely back up, one thing to
dump and load if Subversion releases an incompatible new
version, and so on. Also, you can move data between projects
easily, without losing any historical versioning
information.</para>
<para>The downside of using a single repository is that
different projects may have different requirements in terms of
the repository event triggers, such as needing to send commit
notification emails to different mailing lists, or having
different definitions about what does and does not constitute
a legitimate commit. These aren't insurmountable problems, of
course—it just means that all of your hook scripts have
to be sensitive to the layout of your repository rather than
assuming that the whole repository is associated with a single
group of people. Also, remember that Subversion uses
repository-global revision numbers. While those numbers don't
have any particular magical powers, some folks still don't
like the fact that even though no changes have been made to
their project lately, the youngest revision number for the
repository keeps climbing because other projects are actively
adding new revisions.
<footnote>
<para>Whether founded in ignorance or in poorly considered
concepts about how to derive legitimate software
development metrics, global revision numbers are a silly
thing to fear, and <emphasis>not</emphasis> the kind of
thing you should weigh when deciding how to arrange your
projects and repositories.</para>
</footnote>
</para>
<para>A middle-ground approach can be taken, too. For example,
projects can be grouped by how well they relate to each other.
You might have a few repositories with a handful of projects
in each repository. That way, projects that are likely to
want to share data can do so easily, and as new revisions are
added to the repository, at least the developers know that
those new revisions are at least remotely related to everyone
who uses that repository.</para>
<para>After deciding how to organize your projects with respect
to repositories, you'll probably want to think about directory
hierarchies within the repositories themselves. Because
Subversion uses regular directory copies for branching and
tagging (see <xref linkend="svn.branchmerge"/>), the
Subversion community recommends that you choose a repository
location for each <firstterm>project
root</firstterm>—the <quote>topmost</quote> directory
that contains data related to that project—and then
create three subdirectories beneath that root:
<filename>trunk</filename>, meaning the directory under which
the main project development occurs;
<filename>branches</filename>, which is a directory in which
to create various named branches of the main development line;
and <filename>tags</filename>, which is a collection of tree
snapshots that are created, and perhaps destroyed, but never
changed.
<footnote>
<para>The <filename>trunk</filename>, <filename>tags</filename>,
and <filename>branches</filename> trio is sometimes referred
to as <quote>the TTB directories.</quote></para>
</footnote>
</para>
<para>For example, your repository might look like this:</para>
<screen>
/
calc/
trunk/
tags/
branches/
calendar/
trunk/
tags/
branches/
spreadsheet/
trunk/
tags/
branches/
…
</screen>
<para>Note that it doesn't matter where in your repository each
project root is. If you have only one project per repository,
the logical place to put each project root is at the root of
that project's respective repository. If you have multiple
projects, you might want to arrange them in groups inside the
repository, perhaps putting projects with similar goals or
shared code in the same subdirectory, or maybe just grouping
them alphabetically. Such an arrangement might look
like this:</para>
<screen>
/
utils/
calc/
trunk/
tags/
branches/
calendar/
trunk/
tags/
branches/
…
office/
spreadsheet/
trunk/
tags/
branches/
…
</screen>
<para>Lay out your repository in whatever way you see fit.
Subversion does not expect or enforce a particular layout—in
its eyes, a directory is a directory is a directory.
Ultimately, you should choose the repository arrangement that
meets the needs of the people who work on the projects that
live there.</para>
<para>In the name of full disclosure, though, we'll mention
another very common layout. In this layout, the
<filename>trunk</filename>, <filename>tags</filename>, and
<filename>branches</filename> directories live in the root
directory of your repository, and your projects are in
subdirectories beneath those, like so:</para>
<screen>
/
trunk/
calc/
calendar/
spreadsheet/
…
tags/
calc/
calendar/
spreadsheet/
…
branches/
calc/
calendar/
spreadsheet/
…
</screen>
<para>There's nothing particularly incorrect about such a
layout, but it may or may not seem as intuitive for your
users. Especially in large, multiproject situations with
many users, those users may tend to be familiar with only one
or two of the projects in the repository. But the
projects-as-branch-siblings approach tends to deemphasize project
individuality and focus on the entire set of projects as a
single entity. That's a social issue, though. We like our
originally suggested arrangement for purely practical
reasons—it's easier to ask about (or modify, or migrate
elsewhere) the entire history of a single project when there's
a single repository path that holds the entire
history—past, present, tagged, and branched—for
that project and that project alone.</para>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.basics.hosting">
<title>Deciding Where and How to Host Your Repository</title>
<para>Before creating your Subversion repository, an obvious
question you'll need to answer is where the thing is going to
live. This is strongly connected to myriad other
questions involving how the repository will be accessed (via a
Subversion server or directly), by whom (users behind your
corporate firewall or the whole world out on the open
Internet), what other services you'll be providing around
Subversion (repository browsing interfaces, email-based
commit notification, etc.), your data backup strategy, and so
on.</para>
<para>We cover server choice and configuration in <xref
linkend="svn.serverconfig" />, but the point we'd like to
briefly make here is simply that the answers to some of these
other questions might have implications that force your hand
when deciding where your repository will live. For example,
certain deployment scenarios might require accessing the
repository via a remote filesystem from multiple computers, in
which case (as you'll read in the next section) your choice of
a repository backend data store turns out not to be a choice
at all because only one of the available backends will work
in this scenario.</para>
<para>Addressing each possible way to deploy
Subversion is both impossible and outside the scope of this
book. We simply encourage you to evaluate your options using
these pages and other sources as your reference material and to
plan ahead.</para>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.basics.backends">
<title>Choosing a Data Store</title>
<para>As of version 1.1, Subversion provides two options for the
type of underlying data store—often referred to as
<quote>the backend</quote> or, somewhat confusingly,
<quote>the (versioned) filesystem</quote>—that each
repository uses. One type of data store keeps everything in a
Berkeley DB (or BDB) database environment; repositories that
use this type are often referred to as being
<quote>BDB-backed.</quote> The other type stores data in
ordinary flat files, using a custom format. Subversion
developers have adopted the habit of referring to this latter
data storage mechanism as <firstterm>FSFS</firstterm>
<footnote>
<para>Often pronounced <quote>fuzz-fuzz,</quote> if Jack
Repenning has anything to say about it. (This book,
however, assumes that the reader is thinking
<quote>eff-ess-eff-ess.</quote>)</para>
</footnote>
—a versioned filesystem implementation that uses the
native OS filesystem directly—rather than via a database
library or some other abstraction layer—to store data.</para>
<para><xref linkend="svn.reposadmin.basics.backends.tbl-1" />
gives a comparative overview of Berkeley DB and FSFS
repositories.</para>
<table id="svn.reposadmin.basics.backends.tbl-1">
<title>Repository data store comparison</title>
<tgroup cols="4">
<thead>
<row>
<entry>Category</entry>
<entry>Feature</entry>
<entry>Berkeley DB</entry>
<entry>FSFS</entry>
</row>
</thead>
<tbody>
<row>
<entry morerows="1">Reliability</entry>
<entry>Data integrity</entry>
<entry>When properly deployed, extremely reliable;
Berkeley DB 4.4 brings auto-recovery</entry>
<entry>Older versions had some rarely demonstrated, but
data-destroying bugs</entry>
</row>
<row>
<entry>Sensitivity to interruptions</entry>
<entry>Very; crashes and permission problems can leave the
database <quote>wedged,</quote> requiring journaled
recovery procedures</entry>
<entry>Quite insensitive</entry>
</row>
<row>
<entry morerows="3">Accessibility</entry>
<entry>Usable from a read-only mount</entry>
<entry>No</entry>
<entry>Yes</entry>
</row>
<row>
<entry>Platform-independent storage</entry>
<entry>No</entry>
<entry>Yes</entry>
</row>
<row>
<entry>Usable over network filesystems</entry>
<entry>Generally, no</entry>
<entry>Yes</entry>
</row>
<row>
<entry>Group permissions handling</entry>
<entry>Sensitive to user umask problems; best if accessed
by only one user</entry>
<entry>Works around umask problems</entry>
</row>
<row>
<entry morerows="2">Scalability</entry>
<entry>Repository disk usage</entry>
<entry>Larger (especially if logfiles aren't purged)</entry>
<entry>Smaller</entry>
</row>
<row>
<entry>Number of revision trees</entry>
<entry>Database; no problems</entry>
<entry>Some older native filesystems don't scale well with
thousands of entries in a single directory</entry>
</row>
<row>
<entry>Directories with many files</entry>
<entry>Slower</entry>
<entry>Faster</entry>
</row>
<row>
<entry morerows="1">Performance</entry>
<entry>Checking out latest revision</entry>
<entry>No meaningful difference</entry>
<entry>No meaningful difference</entry>
</row>
<row>
<entry>Large commits</entry>
<entry>Slower overall, but cost is amortized across the
lifetime of the commit</entry>
<entry>Faster overall, but finalization delay may cause
client timeouts</entry>
</row>
</tbody>
</tgroup>
</table>
<para>There are advantages and disadvantages to each of these
two backend types. Neither of them is more
<quote>official</quote> than the other, though the newer FSFS
is the default data store as of Subversion 1.2. Both are
reliable enough to trust with your versioned data. But as you
can see in <xref
linkend="svn.reposadmin.basics.backends.tbl-1" />, the FSFS
backend provides quite a bit more flexibility in terms of its
supported deployment scenarios. More flexibility means you
have to work a little harder to find ways to deploy it
incorrectly. Those reasons—plus the fact that not using
Berkeley DB means there's one fewer component in the
system—largely explain why today almost everyone uses
the FSFS backend when creating new repositories.</para>
<para>Fortunately, most programs that access Subversion
repositories are blissfully ignorant of which backend data
store is in use. And you aren't even necessarily stuck with
your first choice of a data store—in the event that you
change your mind later, Subversion provides ways of migrating
your repository's data into another repository that uses a
different backend data store. We talk more about that later
in this chapter.</para>
<para>The following subsections provide a more detailed look at
the available backend data store types.</para>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.basics.backends.bdb">
<title>Berkeley DB</title>
<para>When the initial design phase of Subversion was in
progress, the developers decided to use Berkeley DB for a
variety of reasons, including its open source license,
transaction support, reliability, performance, API
simplicity, thread safety, support for cursors, and so
on.</para>
<para>Berkeley DB provides real transaction
support—perhaps its most powerful feature. Multiple
processes accessing your Subversion repositories don't have
to worry about accidentally clobbering each other's data.
The isolation provided by the transaction system is such
that for any given operation, the Subversion repository code
sees a static view of the database—not a database that
is constantly changing at the hand of some other
process—and can make decisions based on that view. If
the decision made happens to conflict with what another
process is doing, the entire operation is rolled back as though
it never happened, and Subversion gracefully retries the
operation against a new, updated (and yet still static) view
of the database.</para>
<para>Another great feature of Berkeley DB is <firstterm>hot
backups</firstterm>—the ability to back up the
database environment without taking it
<quote>offline.</quote> We'll discuss how to back up your
repository later in this chapter (in <xref
linkend="svn.reposadmin.maint.backup"/>), but the benefits
of being able to make fully functional copies of your
repositories without any downtime should be obvious.</para>
<para>Berkeley DB is also a very reliable database system when
properly used. Subversion uses Berkeley DB's logging
facilities, which means that the database first writes to
on-disk logfiles a description of any modifications it is
about to make, and then makes the modification itself. This
is to ensure that if anything goes wrong, the database
system can back up to a previous
<firstterm>checkpoint</firstterm>—a location in the
logfiles known not to be corrupt—and replay
transactions until the data is restored to a usable state.
See <xref linkend="svn.reposadmin.maint.diskspace"/> later
in this chapter for more about Berkeley DB logfiles.</para>
<para>But every rose has its thorn, and so we must note some
known limitations of Berkeley DB. First, Berkeley DB
environments are not portable. You cannot simply copy a
Subversion repository that was created on a Unix system onto
a Windows system and expect it to work. While much of the
Berkeley DB database format is architecture-independent,
other aspects of the environment are not.
Second, Subversion uses Berkeley DB in a way that will not
operate on Windows 95/98 systems—if you need to house
a BDB-backed repository on a Windows machine, stick with
Windows 2000 or later.</para>
<para>While Berkeley DB promises to behave correctly on
network shares that meet a particular set of specifications,
<footnote>
<para>Berkeley DB requires that the underlying filesystem
implement strict POSIX locking semantics, and more
importantly, the ability to map files directly into
process memory.</para>
</footnote>
most networked filesystem types and appliances do
<emphasis>not</emphasis> actually meet those requirements.
And in no case can you allow a BDB-backed repository that
resides on a network share to be accessed by multiple
clients of that share at once (which quite often is the
whole point of having the repository live on a network share
in the first place).</para>
<warning>
<para>If you attempt to use Berkeley DB on a noncompliant
remote filesystem, the results are unpredictable—you
may see mysterious errors right away, or it may be months
before you discover that your repository database is
subtly corrupted. You should strongly consider using the
FSFS data store for repositories that need to live on a
network share.</para>
</warning>
<para>Finally, because Berkeley DB is a library linked
directly into Subversion, it's more sensitive to
interruptions than a typical relational database system.
Most SQL systems, for example, have a dedicated server
process that mediates all access to tables. If a program
accessing the database crashes for some reason, the database
daemon notices the lost connection and cleans up any mess
left behind. And because the database daemon is the only
process accessing the tables, applications don't need to
worry about permission conflicts. These things are not the
case with Berkeley DB, however. Subversion (and programs
using Subversion libraries) access the database tables
directly, which means that a program crash can leave the
database in a temporarily inconsistent, inaccessible state.
When this happens, an administrator needs to ask Berkeley DB
to restore to a checkpoint, which is a bit of an annoyance.
Other things can cause a repository to <quote>wedge</quote>
besides crashed processes, such as programs conflicting over
ownership and permissions on the database files.</para>
<note>
<para>Berkeley DB 4.4 brings (to Subversion 1.4 and later)
the ability for Subversion to automatically and
transparently recover Berkeley DB environments in need of
such recovery. When a Subversion process attaches to a
repository's Berkeley DB environment, it uses some process
accounting mechanisms to detect any unclean disconnections
by previous processes, performs any necessary recovery,
and then continues on as though nothing happened. This
doesn't completely eliminate instances of repository
wedging, but it does drastically reduce the amount of
human interaction required to recover from them.</para>
</note>
<para>So while a Berkeley DB repository is quite fast and
scalable, it's best used by a single server process running
as one user—such as Apache's <command>httpd</command>
or <command>svnserve</command> (see <xref
linkend="svn.serverconfig"/>)—rather than accessing it
as many different users via <literal>file://</literal> or
<literal>svn+ssh://</literal> URLs. If you're accessing a Berkeley
DB repository directly as multiple users, be sure to read
<xref linkend="svn.serverconfig.multimethod"/> later in this
chapter.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.basics.backends.fsfs">
<title>FSFS</title>
<para>In mid-2004, a second type of repository storage
system—one that doesn't use a database at
all—came into being. An FSFS repository stores the
changes associated with a revision in a single file, and so
all of a repository's revisions can be found in a single
subdirectory full of numbered files. Transactions are
created in separate subdirectories as individual files.
When complete, the transaction file is renamed and moved
into the revisions directory, thus guaranteeing that commits
are atomic. And because a revision file is permanent and
unchanging, the repository also can be backed up while
<quote>hot,</quote> just like a BDB-backed
repository.</para>
<para>The FSFS revision files describe a revision's
directory structure, file contents, and deltas against files
in other revision trees. Unlike a Berkeley DB database,
this storage format is portable across different operating
systems and isn't sensitive to CPU architecture. Because
no journaling or shared-memory files are being used, the
repository can be safely accessed over a network filesystem
and examined in a read-only environment. The lack of
database overhead also means the overall repository
size is a bit smaller.</para>
<para>FSFS has different performance characteristics, too.
When committing a directory with a huge number of files,
FSFS is able to more quickly append directory entries. On
the other hand, FSFS writes the latest version of a file as
a delta against an earlier version, which means that
checking out the latest tree is a bit slower than fetching
the full-texts stored in a Berkeley DB HEAD revision. FSFS
also has a longer delay when finalizing a commit, which
could in extreme cases cause clients to time out while
waiting for a response.</para>
<para>The most important distinction, however, is FSFS's
imperviousness to wedging when something goes wrong. If a
process using a Berkeley DB database runs into a permissions
problem or suddenly crashes, the database can be left in an
unusable state until an administrator recovers it. If the
same scenarios happen to a process using an FSFS repository,
the repository isn't affected at all. At worst, some
transaction data is left behind.</para>
<para>The only real argument against FSFS is its relative
immaturity compared to Berkeley DB. Unlike Berkeley DB,
which has years of history, its own dedicated development
team, and, now, Oracle's mighty name attached to it,
<footnote>
<para>Oracle bought Sleepycat and its flagship software,
Berkeley DB, on Valentine's Day in 2006.</para>
</footnote>
FSFS is a newer bit of engineering. Prior to Subversion
1.4, it was still shaking out some pretty serious data
integrity bugs, which, while triggered in only very rare
cases, nonetheless did occur. That said, FSFS has quickly
become the backend of choice for some of the largest public
and private Subversion repositories, and it promises a lower
barrier to entry for Subversion across the board.</para>
</sect3>
</sect2>
</sect1>
<!-- ================================================================= -->
<!-- ================================================================= -->
<!-- ================================================================= -->
<sect1 id="svn.reposadmin.create">
<title>Creating and Configuring Your Repository</title>
<para>Earlier in this chapter (in <xref linkend="svn.reposadmin.planning" />), we
looked at some of the important decisions that should be made
before creating and configuring your Subversion repository.
Now, we finally get to get our hands dirty! In this section,
we'll see how to actually create a Subversion repository and
configure it to perform custom actions when special repository
events occur.</para>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.basics.creating">
<title>Creating the Repository</title>
<para>Subversion repository creation is an incredibly simple
task. The <command>svnadmin</command> utility that comes with
Subversion provides a subcommand (<command>svnadmin
create</command>) for doing just that.</para>
<screen>
$ # Create a repository
$ svnadmin create /var/svn/repos
$
</screen>
<para>This creates a new repository in the directory
<filename>/var/svn/repos</filename>, and with the default
filesystem data store. Prior to Subversion 1.2, the default
was to use Berkeley DB; the default is now FSFS. You can
explicitly choose the filesystem type using the
<option>--fs-type</option> argument, which accepts as a
parameter either <literal>fsfs</literal> or
<literal>bdb</literal>.</para>
<screen>
$ # Create an FSFS-backed repository
$ svnadmin create --fs-type fsfs /var/svn/repos
$
</screen>
<screen>
# Create a Berkeley-DB-backed repository
$ svnadmin create --fs-type bdb /var/svn/repos
$
</screen>
<para>After running this simple command, you have a Subversion
repository.</para>
<tip>
<para>The path argument to <command>svnadmin</command> is just
a regular filesystem path and not a URL like the
<command>svn</command> client program uses when referring to
repositories. Both <command>svnadmin</command> and
<command>svnlook</command> are considered server-side
utilities—they are used on the machine where the
repository resides to examine or modify aspects of the
repository, and are in fact unable to perform tasks across a
network. A common mistake made by Subversion newcomers is
trying to pass URLs (even <quote>local</quote>
<literal>file://</literal> ones) to these two programs.</para>
</tip>
<para>Present in the <filename>db/</filename> subdirectory of
your repository is the implementation of the versioned
filesystem. Your new repository's versioned filesystem begins
life at revision 0, which is defined to consist of nothing but
the top-level root (<filename>/</filename>) directory.
Initially, revision 0 also has a single revision property,
<literal>svn:date</literal>, set to the time at which the
repository was created.</para>
<para>Now that you have a repository, it's time to customize
it.</para>
<warning>
<para>While some parts of a Subversion repository—such
as the configuration files and hook scripts—are meant
to be examined and modified manually, you shouldn't (and
shouldn't need to) tamper with the other parts of the
repository <quote>by hand.</quote> The
<command>svnadmin</command> tool should be sufficient for
any changes necessary to your repository, or you can look to
third-party tools (such as Berkeley DB's tool suite) for
tweaking relevant subsections of the repository. Do
<emphasis>not</emphasis> attempt manual manipulation of your
version control history by poking and prodding around in
your repository's data store files!</para>
</warning>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.create.hooks">
<title>Implementing Repository Hooks</title>
<para>A <firstterm>hook</firstterm> is a program triggered by
some repository event, such as the creation of a new revision
or the modification of an unversioned property. Some hooks
(the so-called <quote>pre hooks</quote>) run in advance of a
repository operation and provide a means by which to both
report what is about to happen and prevent it from
happening at all. Other hooks (the <quote>post hooks</quote>)
run after the completion of a repository event and are useful
for performing tasks that examine—but don't
modify—the repository. Each hook is handed enough
information to tell what that event is (or was), the specific
repository changes proposed (or completed), and the username
of the person who triggered the event.</para>
<para>The <filename>hooks</filename> subdirectory is, by
default, filled with templates for various repository
hooks:</para>
<screen>
$ ls repos/hooks/
post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmpl
post-lock.tmpl pre-commit.tmpl pre-unlock.tmpl
post-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl
$
</screen>
<para>There is one template for each hook that the Subversion
repository supports; by examining the contents of those
template scripts, you can see what triggers each script
to run and what data is passed to that script. Also present
in many of these templates are examples of how one might use
that script, in conjunction with other Subversion-supplied
programs, to perform common useful tasks. To actually install
a working hook, you need only place some executable program or
script into the <filename>repos/hooks</filename> directory,
which can be executed as the name (such as
<command>start-commit</command> or
<command>post-commit</command>) of the hook.</para>
<para>On Unix platforms, this means supplying a script or
program (which could be a shell script, a Python program, a
compiled C binary, or any number of other things) named
exactly like the name of the hook. Of course, the template
files are present for more than just informational
purposes—the easiest way to install a hook on Unix
platforms is to simply copy the appropriate template file to a
new file that lacks the <filename>.tmpl</filename> extension,
customize the hook's contents, and ensure that the script is
executable. Windows, however, uses file extensions to
determine whether a program is executable, so you would
need to supply a program whose basename is the name of the
hook and whose extension is one of the special extensions
recognized by Windows for executable programs, such as
<filename>.exe</filename> for programs and
<filename>.bat</filename> for batch files.</para>
<tip>
<para>For security reasons, the Subversion repository executes
hook programs with an empty environment—that is, no
environment variables are set at all, not even
<literal>$PATH</literal> (or <literal>%PATH%</literal>,
under Windows). Because of this, many administrators
are baffled when their hook program runs fine by hand, but
doesn't work when run by Subversion. Be sure to explicitly
set any necessary environment variables in your hook program
and/or use absolute paths to programs.</para>
</tip>
<para>Subversion executes hooks as the same user who owns the
process that is accessing the Subversion repository. In most
cases, the repository is being accessed via a Subversion
server, so this user is the same user as whom the server
runs on the system. The hooks themselves will need to be
configured with OS-level permissions that allow that user to
execute them. Also, this means that any programs or files
(including the Subversion repository) accessed directly
or indirectly by the hook will be accessed as the same user.
In other words, be alert to potential permission-related
problems that could prevent the hook from performing the tasks
it is designed to perform.</para>
<para>There are serveral hooks implemented by the Subversion
repository, and you can get details about each of them in
<xref linkend="svn.ref.reposhooks" />. As a repository
administrator, you'll need to decide which hooks you wish
to implement (by way of providing an appropriately named and
permissioned hook program), and how. When you make this
decision, keep in mind
the big picture of how your repository is deployed.
For example, if you are using server configuration
to determine which users are permitted to commit
changes to your repository, you don't need to do this
sort of access control via the hook system.</para>
<para>There is no shortage of Subversion hook programs and
scripts that are freely available either from the Subversion community
itself or elsewhere. These scripts cover a wide range of
utility—basic access control, policy adherence checking,
issue tracker integration, email- or syndication-based commit
notification, and beyond. Or, if you wish to write your own,
see <xref linkend="svn.developer" />.</para>
<warning>
<para>While hook scripts can do almost
anything, there is one dimension in which hook script
authors should show restraint: do <emphasis>not</emphasis>
modify a commit transaction using hook scripts. While it
might be tempting to use hook scripts to automatically
correct errors, shortcomings, or policy violations present
in the files being committed, doing so can cause problems.
Subversion keeps client-side caches of certain bits of
repository data, and if you change a commit transaction in
this way, those caches become indetectably stale. This
inconsistency can lead to surprising and unexpected
behavior. Instead of modifying the transaction, you should
simply <emphasis>validate</emphasis> the transaction in the
<filename>pre-commit</filename> hook and reject the commit
if it does not meet the desired requirements. As a
bonus, your users will learn the value of careful,
compliance-minded work habits.</para>
</warning>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.create.bdb">
<title>Berkeley DB Configuration</title>
<para>A Berkeley DB environment is an encapsulation of one or
more databases, logfiles, region files, and configuration
files. The Berkeley DB environment has its own set of default
configuration values for things such as the number of database
locks allowed to be taken out at any given time, the maximum
size of the journaling logfiles, and so on. Subversion's
filesystem logic additionally chooses default values for some
of the Berkeley DB configuration options. However, sometimes
your particular repository, with its unique collection of data
and access patterns, might require a different set of
configuration option values.</para>
<para>The producers of Berkeley DB understand that different
applications and database environments have different
requirements, so they have provided a mechanism for overriding
at runtime many of the configuration values for the Berkeley
DB environment. BDB checks for the presence of a file named
<filename>DB_CONFIG</filename> in the environment directory
(namely, the repository's <filename>db</filename>
subdirectory), and parses the options found in that file.
Subversion itself creates this file when it creates the rest
of the repository. The file initially contains some default
options, as well as pointers to the Berkeley DB online
documentation so that you can read about what those options do. Of
course, you are free to add any of the supported Berkeley DB
options to your <filename>DB_CONFIG</filename> file. Just be
aware that while Subversion never attempts to read or
interpret the contents of the file and makes no direct use of
the option settings in it, you'll want to avoid any
configuration changes that may cause Berkeley DB to behave in
a fashion that is at odds with what Subversion might expect.
Also, changes made to <filename>DB_CONFIG</filename> won't
take effect until you recover the database environment (using
<command>svnadmin recover</command>).</para>
</sect2>
</sect1>
<!-- ================================================================= -->
<!-- ================================================================= -->
<!-- ================================================================= -->
<sect1 id="svn.reposadmin.maint">
<title>Repository Maintenance</title>
<para>Maintaining a Subversion repository can be daunting, mostly
due to the complexities inherent in systems that have a database
backend. Doing the task well is all about knowing the
tools—what they are, when to use them, and how. This
section will introduce you to the repository administration
tools provided by Subversion and discuss how to wield them to
accomplish tasks such as repository data migration, upgrades,
backups, and cleanups.</para>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.tk">
<title>An Administrator's Toolkit</title>
<para>Subversion provides a handful of utilities useful for
creating, inspecting, modifying, and repairing your repository.
Let's look more closely at each of those tools. Afterward,
we'll briefly examine some of the utilities included in the
Berkeley DB distribution that provide functionality specific
to your repository's database backend not otherwise provided
by Subversion's own tools.</para>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.svnadmin">
<title>svnadmin</title>
<para>The <command>svnadmin</command> program is the
repository administrator's best friend. Besides providing
the ability to create Subversion repositories, this program
allows you to perform several maintenance operations on
those repositories. The syntax of
<command>svnadmin</command> is similar to that of other
Subversion command-line programs:</para>
<screen>
$ svnadmin help
general usage: svnadmin SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]
Type 'svnadmin help <subcommand>' for help on a specific subcommand.
Type 'svnadmin --version' to see the program version and FS modules.
Available subcommands:
crashtest
create
deltify
…
</screen>
<para>Previously in this chapter (in <xref
linkend="svn.reposadmin.basics.creating"/>), we were
introduced to the <command>svnadmin create</command>
subcommand. Most of the other <command>svnadmin</command>
subcommands we will cover later in this chapter. And you
can consult <xref linkend="svn.ref.svnadmin" /> for a full
rundown of subcommands and what each of them offers.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.svnlook">
<title>svnlook</title>
<para><command>svnlook</command> is a tool provided by
Subversion for examining the various revisions and
<firstterm>transactions</firstterm> (which are revisions
in the making) in a repository. No part of this program
attempts to change the repository. <command>svnlook</command>
is typically used by the repository hooks for reporting the
changes that are about to be committed (in the case of the
<command>pre-commit</command> hook) or that were just
committed (in the case of the <command>post-commit</command>
hook) to the repository. A repository administrator may use
this tool for diagnostic purposes.</para>
<para><command>svnlook</command> has a straightforward
syntax:</para>
<screen>
$ svnlook help
general usage: svnlook SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]
Note: any subcommand which takes the '--revision' and '--transaction'
options will, if invoked without one of those options, act on
the repository's youngest revision.
Type 'svnlook help <subcommand>' for help on a specific subcommand.
Type 'svnlook --version' to see the program version and FS modules.
…
</screen>
<para>Most of <command>svnlook</command>'s
subcommands can operate on either a revision or a
transaction tree, printing information about the tree
itself, or how it differs from the previous revision of the
repository. You use the <option>--revision</option>
(<option>-r</option>) and <option>--transaction</option>
(<option>-t</option>) options to specify which revision or
transaction, respectively, to examine. In the absence of
both the <option>--revision</option> (<option>-r</option>)
and <option>--transaction</option> (<option>-t</option>)
options, <command>svnlook</command> will examine the
youngest (or <literal>HEAD</literal>) revision in the
repository. So the following two commands do exactly the
same thing when 19 is the youngest revision in the
repository located at
<filename>/var/svn/repos</filename>:</para>
<screen>
$ svnlook info /var/svn/repos
$ svnlook info /var/svn/repos -r 19
</screen>
<para>One exception to these rules about subcommands is
the <command>svnlook youngest</command> subcommand, which
takes no options and simply prints out the repository's
youngest revision number:</para>
<screen>
$ svnlook youngest /var/svn/repos
19
$
</screen>
<note>
<para>Keep in mind that the only transactions you can browse
are uncommitted ones. Most repositories will have no such
transactions because transactions are usually either
committed (in which case, you should access them as
revision with the <option>--revision</option>
(<option>-r</option>) option) or aborted and
removed.</para>
</note>
<para>Output from <command>svnlook</command> is designed to be
both human- and machine-parsable. Take, as an example, the
output of the <command>svnlook info</command> subcommand:</para>
<screen>
$ svnlook info /var/svn/repos
sally
2002-11-04 09:29:13 -0600 (Mon, 04 Nov 2002)
27
Added the usual
Greek tree.
$
</screen>
<para>The output of <command>svnlook info</command> consists
of the following, in the order given:</para>
<orderedlist>
<listitem>
<para>The author, followed by a newline</para>
</listitem>
<listitem>
<para>The date, followed by a newline</para>
</listitem>
<listitem>
<para>The number of characters in the log message,
followed by a newline</para>
</listitem>
<listitem>
<para>The log message itself, followed by a newline</para>
</listitem>
</orderedlist>
<para>This output is human-readable, meaning items such as the
datestamp are displayed using a textual representation
instead of something more obscure (such as the number of
nanoseconds since the Tastee Freez guy drove by). But the
output is also machine-parsable—because the log
message can contain multiple lines and be unbounded in
length, <command>svnlook</command> provides the length of
that message before the message itself. This allows scripts
and other wrappers around this command to make intelligent
decisions about the log message, such as how much memory to
allocate for the message, or at least how many bytes to skip
in the event that this output is not the last bit of data in
the stream.</para>
<para><command>svnlook</command> can perform a variety of
other queries: displaying subsets of bits of information
we've mentioned previously, recursively listing versioned
directory trees, reporting which paths were modified in a
given revision or transaction, showing textual and property
differences made to files and directories, and so on. See
<xref linkend="svn.ref.svnlook" /> for a full reference of
<command>svnlook</command>'s features.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.svndumpfilter">
<title>svndumpfilter</title>
<para>While it won't be the most commonly used tool at the
administrator's disposal, <command>svndumpfilter</command>
provides a very particular brand of useful
functionality—the ability to quickly and easily modify
streams of Subversion repository history data by acting as a
path-based filter.</para>
<para>The syntax of <command>svndumpfilter</command> is as
follows:</para>
<screen>
$ svndumpfilter help
general usage: svndumpfilter SUBCOMMAND [ARGS & OPTIONS ...]
Type "svndumpfilter help <subcommand>" for help on a specific subcommand.
Type 'svndumpfilter --version' to see the program version.
Available subcommands:
exclude
include
help (?, h)
</screen>
<para>There are only two interesting subcommands:
<command>svndumpfilter exclude</command> and
<command>svndumpfilter include</command>. They allow you to
make the choice between implicit or explicit inclusion of
paths in the stream. You can learn more about these
subcommands and <command>svndumpfilter</command>'s unique
purpose later in this chapter, in <xref
linkend="svn.reposadmin.maint.filtering" />.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.svnsync">
<title>svnsync</title>
<para>The <command>svnsync</command> program, which is new to
the 1.4 release of Subversion, provides all the
functionality required for maintaining a read-only mirror of
a Subversion repository. The program really has one
job—to transfer one repository's versioned history
into another repository. And while there are few ways to do
that, its primary strength is that it can operate
remotely—the <quote>source</quote> and
<quote>sink</quote>
<footnote>
<para>Or is that, the <quote>sync</quote>?</para>
</footnote>
repositories may be on different computers from each other
and from <command>svnsync</command> itself.</para>
<para>As you might expect, <command>svnsync</command> has a
syntax that looks very much like every other program we've
mentioned in this chapter:</para>
<screen>
$ svnsync help
general usage: svnsync SUBCOMMAND DEST_URL [ARGS & OPTIONS ...]
Type 'svnsync help <subcommand>' for help on a specific subcommand.
Type 'svnsync --version' to see the program version and RA modules.
Available subcommands:
initialize (init)
synchronize (sync)
copy-revprops
help (?, h)
$
</screen>
<para>We talk more about replicating repositories with
<command>svnsync</command> later in this chapter (see <xref
linkend="svn.reposadmin.maint.replication" />).</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.fsfsreshard">
<title>fsfs-reshard.py</title>
<para>While not an official member of the Subversion
toolchain, the <command>fsfs-reshard.py</command> script
(found in the <filename>tools/server-side</filename>
directory of the Subversion source distribution) is a useful
performance tuning tool for administrators of FSFS-backed
Subversion repositories. FSFS repositories contain files
that describe the changes made in a single revision, and
files that contain the revision properties associated with
a single revision. Repositories created in versions of
Subversion prior to 1.5 keep these files in two
directories—one for each type of file. As new
revisions are committed to the repository, Subversion drops
more files into these two directories—over time, the
number of these files in each directory can grow to be quite
large. This has been observed to cause performance problems
on certain network-based filesystems.</para>
<para>Subversion 1.5 creates FSFS-backed repositories using a
slightly modified layout in which the contents of these two
directories are <firstterm>sharded</firstterm>, or scattered
across several subdirectories. This can greatly reduce the
time it takes the system to locate any one of these files,
and therefore increases the overall performance of
Subversion when reading from the repository. The number of
subdirectories used to house these files is configurable,
though, and that's where
<command>fsfs-reshard.py</command> comes in. This script
reshuffles the repository's file structure into a new
arrangement that reflects the requested number of sharding
subdirectories. This is especially useful for converting an
older Subversion repository into the new Subversion 1.5
sharded layout (which Subversion will not automatically do
for you) or for fine-tuning an already sharded
repository.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.tk.bdbutil">
<title>Berkeley DB utilities</title>
<para>If you're using a Berkeley DB repository, all of
your versioned filesystem's structure and data live in a set
of database tables within the <filename>db/</filename>
subdirectory of your repository. This subdirectory is a
regular Berkeley DB environment directory and can therefore
be used in conjunction with any of the Berkeley database
tools, typically provided as part of the Berkeley DB
distribution.</para>
<para>For day-to-day Subversion use, these tools are
unnecessary. Most of the functionality typically needed for
Subversion repositories has been duplicated in the
<command>svnadmin</command> tool. For example,
<command>svnadmin list-unused-dblogs</command> and
<command>svnadmin list-dblogs</command> perform a
subset of what is provided by the Berkeley
<command>db_archive</command> utility, and <command>svnadmin
recover</command> reflects the common use cases of the
<command>db_recover</command> utility.</para>
<para>However, there are still a few Berkeley DB utilities
that you might find useful. The <command>db_dump</command>
and <command>db_load</command> programs write and read,
respectively, a custom file format that describes the keys
and values in a Berkeley DB database. Since Berkeley
databases are not portable across machine architectures,
this format is a useful way to transfer those databases from
machine to machine, irrespective of architecture or
operating system. As we describe later in this chapter, you
can also use <command>svnadmin dump</command> and
<command>svnadmin load</command> for similar purposes, but
<command>db_dump</command> and <command>db_load</command>
can do certain jobs just as well and much faster. They can
also be useful if the experienced Berkeley DB hacker needs
to do in-place tweaking of the data in a BDB-backed
repository for some reason, which is something Subversion's
utilities won't allow. Also, the <command>db_stat</command>
utility can provide useful information about the status of
your Berkeley DB environment, including detailed statistics
about the locking and storage subsystems.</para>
<para>For more information on the Berkeley DB tool chain,
visit the documentation section of the Berkeley DB section
of Oracle's web site, located at <ulink
url="http://www.oracle.com/technology/documentation/berkeley-db/db/"
/>.</para>
</sect3>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.setlog">
<title>Commit Log Message Correction</title>
<para>Sometimes a user will have an error in her log message (a
misspelling or some misinformation, perhaps). If the
repository is configured (using the
<literal>pre-revprop-change</literal> hook; see <xref
linkend="svn.reposadmin.create.hooks"/>) to accept changes to
this log message after the commit is finished, the user
can <quote>fix</quote> her log message remotely using
<command>svn propset</command> (see <xref
linkend="svn.ref.svn.c.propset"/>). However, because of the
potential to lose information forever, Subversion repositories
are not, by default, configured to allow changes to
unversioned properties—except by an
administrator.</para>
<para>If a log message needs to be changed by an administrator,
this can be done using <command>svnadmin setlog</command>.
This command changes the log message (the
<literal>svn:log</literal> property) on a given revision of a
repository, reading the new value from a provided file.</para>
<screen>
$ echo "Here is the new, correct log message" > newlog.txt
$ svnadmin setlog myrepos newlog.txt -r 388
</screen>
<para>The <command>svnadmin setlog</command> command, by
default, is
still bound by the same protections against modifying
unversioned properties as a remote client is—the
<literal>pre-</literal> and
<literal>post-revprop-change</literal> hooks are still
triggered, and therefore must be set up to accept changes of
this nature. But an administrator can get around these
protections by passing the <option>--bypass-hooks</option>
option to the <command>svnadmin setlog</command> command.</para>
<warning>
<para>Remember, though, that by bypassing the hooks, you are
likely avoiding such things as email notifications of
property changes, backup systems that track unversioned
property changes, and so on. In other words, be very
careful about what you are changing, and how you change
it.</para>
</warning>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.diskspace">
<title>Managing Disk Space</title>
<para>While the cost of storage has dropped incredibly in the
past few years, disk usage is still a valid concern for
administrators seeking to version large amounts of data.
Every bit of version history information stored in the live
repository needs to be backed up
elsewhere, perhaps multiple times as part of rotating backup
schedules. It is useful to know what pieces of Subversion's
repository data need to remain on the live site, which need to
be backed up, and which can be safely removed.</para>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.diskspace.deltas">
<title>How Subversion saves disk space</title>
<para>To keep the repository small,
Subversion uses <firstterm>deltification</firstterm> (or
deltified storage) within the repository
itself. Deltification involves encoding the representation
of a chunk of data as a collection of differences against
some other chunk of data. If the two pieces of data are
very similar, this deltification results in storage savings
for the deltified chunk—rather than taking up space
equal to the size of the original data, it takes up only
enough space to say, <quote>I look just like this other
piece of data over here, except for the following couple of
changes.</quote> The result is that most of the repository
data that tends to be bulky—namely, the contents of
versioned files—is stored at a much smaller size than
the original full-text representation of that
data. And for repositories created with Subversion 1.4 or
later, the space savings are even better—now those
full-text representations of file contents are themselves
compressed.</para>
<note>
<para>Because all of the data that is subject to
deltification in a BDB-backed repository is stored in a
single Berkeley DB database file, reducing the size of the
stored values will not immediately reduce the size of the
database file itself. Berkeley DB will, however, keep
internal records of unused areas of the database file and
consume those areas first before growing the size of the
database file. So while deltification doesn't produce
immediate space savings, it can drastically slow future
growth of the database.</para>
</note>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.diskspace.deadtxns">
<title>Removing dead transactions</title>
<para>Though they are uncommon, there are circumstances in
which a Subversion commit process might fail, leaving behind
in the repository the remnants of the revision-to-be that
wasn't—an uncommitted transaction and all the file and
directory changes associated with it. This could happen for
several reasons: perhaps the client operation was
inelegantly terminated by the user, or a network failure
occurred in the middle of an operation.
Regardless of the reason, dead transactions can happen.
They don't do any real harm, other than consuming disk
space. A fastidious administrator may nonetheless wish to
remove them.</para>
<para>You can use the <command>svnadmin lstxns</command>
command to list the names of the currently outstanding
transactions:</para>
<screen>
$ svnadmin lstxns myrepos
19
3a1
a45
$
</screen>
<para>Each item in the resultant output can then be used with
<command>svnlook</command> (and its
<option>--transaction</option> (<option>-t</option>) option)
to determine who created the transaction, when it was
created, what types of changes were made in the
transaction—information that is helpful in determining
whether the transaction is a safe candidate for
removal! If you do indeed want to remove a transaction, its
name can be passed to <command>svnadmin rmtxns</command>,
which will perform the cleanup of the transaction. In fact,
<command>svnadmin rmtxns</command> can take its input
directly from the output of
<command>svnadmin lstxns</command>!</para>
<screen>
$ svnadmin rmtxns myrepos `svnadmin lstxns myrepos`
$
</screen>
<para>If you use these two subcommands like this, you should
consider making your repository temporarily inaccessible to
clients. That way, no one can begin a legitimate
transaction before you start your cleanup. <xref
linkend="svn.reposadmin.maint.diskspace.deadtxns.ex-1" />
contains a bit of shell-scripting that can quickly generate
information about each outstanding transaction in your
repository.</para>
<example id="svn.reposadmin.maint.diskspace.deadtxns.ex-1">
<title>txn-info.sh (reporting outstanding transactions)</title>
<programlisting>
#!/bin/sh
### Generate informational output for all outstanding transactions in
### a Subversion repository.
REPOS="${1}"
if [ "x$REPOS" = x ] ; then
echo "usage: $0 REPOS_PATH"
exit
fi
for TXN in `svnadmin lstxns ${REPOS}`; do
echo "---[ Transaction ${TXN} ]-------------------------------------------"
svnlook info "${REPOS}" -t "${TXN}"
done
</programlisting>
</example>
<para>The output of the script is basically a concatenation of
several chunks of <command>svnlook info</command> output
(see <xref linkend="svn.reposadmin.maint.tk.svnlook"/>) and
will look something like this:</para>
<screen>
$ txn-info.sh myrepos
---[ Transaction 19 ]-------------------------------------------
sally
2001-09-04 11:57:19 -0500 (Tue, 04 Sep 2001)
0
---[ Transaction 3a1 ]-------------------------------------------
harry
2001-09-10 16:50:30 -0500 (Mon, 10 Sep 2001)
39
Trying to commit over a faulty network.
---[ Transaction a45 ]-------------------------------------------
sally
2001-09-12 11:09:28 -0500 (Wed, 12 Sep 2001)
0
$
</screen>
<para>A long-abandoned transaction usually represents some
sort of failed or interrupted commit. A transaction's
datestamp can provide interesting information—for
example, how likely is it that an operation begun nine
months ago is still active?</para>
<para>In short, transaction cleanup decisions need not be made
unwisely. Various sources of information—including
Apache's error and access logs, Subversion's operational
logs, Subversion revision history, and so on—can be
employed in the decision-making process. And of course, an
administrator can often simply communicate with a seemingly
dead transaction's owner (via email, e.g.) to verify
that the transaction is, in fact, in a zombie state.</para>
</sect3>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<sect3 id="svn.reposadmin.maint.diskspace.bdblogs">
<title>Purging unused Berkeley DB logfiles</title>
<para>Until recently, the largest offender of disk space usage
with respect to BDB-backed Subversion repositories were the
logfiles in which Berkeley DB performs its prewrites before
modifying the actual database files. These files capture
all the actions taken along the route of changing the
database from one state to another—while the database
files, at any given time, reflect a particular state, the
logfiles contain all of the many changes along the way
<emphasis>between</emphasis> states. Thus, they can grow
and accumulate quite rapidly.</para>
<para>Fortunately, beginning with the 4.2 release of Berkeley
DB, the database environment has the ability to remove its
own unused logfiles automatically. Any
repositories created using <command>svnadmin</command>
when compiled against Berkeley DB version 4.2 or later
will be configured for this automatic logfile removal. If
you don't want this feature enabled, simply pass the
<option>--bdb-log-keep</option> option to the
<command>svnadmin create</command> command. If you forget
to do this or change your mind at a later time, simply edit
the <filename>DB_CONFIG</filename> file found in your
repository's <filename>db</filename> directory, comment out
the line that contains the <literal>set_flags
DB_LOG_AUTOREMOVE</literal> directive, and then run
<command>svnadmin recover</command> on your repository to
force the configuration changes to take effect. See <xref
linkend="svn.reposadmin.create.bdb"/> for more information about
database configuration.</para>
<para>Without some sort of automatic logfile removal in
place, logfiles will accumulate as you use your repository.
This is actually somewhat of a feature of the database
system—you should be able to recreate your entire
database using nothing but the logfiles, so these files can
be useful for catastrophic database recovery. But
typically, you'll want to archive the logfiles that are no
longer in use by Berkeley DB, and then remove them from disk
to conserve space. Use the <command>svnadmin
list-unused-dblogs</command> command to list the unused
logfiles:</para>
<screen>
$ svnadmin list-unused-dblogs /var/svn/repos
/var/svn/repos/log.0000000031
/var/svn/repos/log.0000000032
/var/svn/repos/log.0000000033
…
$ rm `svnadmin list-unused-dblogs /var/svn/repos`
## disk space reclaimed!
</screen>
<warning>
<para>BDB-backed repositories whose logfiles are used as
part of a backup or disaster recovery plan should
<emphasis>not</emphasis> make use of the logfile
autoremoval feature. Reconstruction of a repository's
data from logfiles can only be accomplished only when
<emphasis>all</emphasis> the logfiles are available. If
some of the logfiles are removed from disk before the
backup system has a chance to copy them elsewhere, the
incomplete set of backed-up logfiles is essentially
useless.</para> </warning>
</sect3>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.recovery">
<title>Berkeley DB Recovery</title>
<para>As mentioned in <xref
linkend="svn.reposadmin.basics.backends.bdb"/>, a Berkeley DB
repository can sometimes be left in a frozen state if not closed
properly. When this happens, an administrator needs to rewind
the database back into a consistent state. This is unique to
BDB-backed repositories, though—if you are using
FSFS-backed ones instead, this won't apply to you. And for
those of you using Subversion 1.4 with Berkeley DB 4.4 or
later, you should find that Subversion has become much more
resilient in these types of situations. Still, wedged
Berkeley DB repositories do occur, and an administrator needs
to know how to safely deal with this circumstance.</para>
<para>To protect the data in your repository, Berkeley
DB uses a locking mechanism. This mechanism ensures that
portions of the database are not simultaneously modified by
multiple database accessors, and that each process sees the
data in the correct state when that data is being read from
the database. When a process needs to change something in the
database, it first checks for the existence of a lock on the
target data. If the data is not locked, the process locks the
data, makes the change it wants to make, and then unlocks the
data. Other processes are forced to wait until that lock is
removed before they are permitted to continue accessing that
section of the database. (This has nothing to do with the
locks that you, as a user, can apply to versioned files within
the repository; we try to clear up the confusion caused by
this terminology collision in the sidebar <xref
linkend="svn.advanced.locking.meanings" />.)</para>
<para>In the course of using your Subversion repository, fatal
errors or interruptions can prevent a process from having the
chance to remove the locks it has placed in the database. The
result is that the backend database system gets
<quote>wedged.</quote> When this happens, any attempts to
access the repository hang indefinitely (since each new
accessor is waiting for a lock to go away—which isn't
going to happen).</para>
<para>If this happens to your repository, don't panic. The
Berkeley DB filesystem takes advantage of database
transactions, checkpoints, and prewrite journaling to
ensure that only the most catastrophic of events
<footnote>
<para>For example, hard drive + huge electromagnet = disaster.</para>
</footnote>
can permanently destroy a database environment. A
sufficiently paranoid repository administrator will have made
off-site backups of the repository data in some fashion, but
don't head off to the tape backup storage closet just yet.</para>
<para>Instead, use the following recipe to attempt to
<quote>unwedge</quote> your repository:</para>
<orderedlist>
<listitem>
<para>Make sure no processes are accessing (or
attempting to access) the repository. For networked
repositories, this also means shutting down the Apache HTTP
Server or svnserve daemon.</para>
</listitem>
<listitem>
<para>Become the user who owns and manages the repository.
This is important, as recovering a repository while
running as the wrong user can tweak the permissions of the
repository's files in such a way that your repository will
still be inaccessible even after it is
<quote>unwedged.</quote></para>
</listitem>
<listitem>
<para>Run the command <userinput>svnadmin recover
/var/svn/repos</userinput>. You should see output such as
this:</para>
<screen>
Repository lock acquired.
Please wait; recovering the repository may take some time...
Recovery completed.
The latest repos revision is 19.
</screen>
<para>This command may take many minutes to complete.</para>
</listitem>
<listitem>
<para>Restart the server process.</para>
</listitem>
</orderedlist>
<para>This procedure fixes almost every case of repository
wedging. Make sure that you run this command as the user that
owns and manages the database, not just as
<literal>root</literal>. Part of the recovery process might
involve re-creating from scratch various database files (shared
memory regions, e.g.). Recovering as
<literal>root</literal> will create those files such that they
are owned by <literal>root</literal>, which means that even
after you restore connectivity to your repository, regular
users will be unable to access it.</para>
<para>If the previous procedure, for some reason, does not
successfully unwedge your repository, you should do two
things. First, move your broken repository directory aside
(perhaps by renaming it to something like
<filename>repos.BROKEN</filename>) and then restore your
latest backup of it. Then, send an email to the Subversion
users mailing list (at <email>users@subversion.tigris.org</email>)
describing your problem in detail. Data integrity is an
extremely high priority to the Subversion developers.</para>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.migrate">
<title>Migrating Repository Data Elsewhere</title>
<para>A Subversion filesystem has its data spread throughout
files in the repository, in a fashion generally
understood by (and of interest to) only the Subversion
developers themselves. However, circumstances may arise that
call for all, or some subset, of that data to be copied or
moved into another repository.</para>
<para>Subversion provides such functionality by way of
<firstterm>repository dump streams</firstterm>. A repository
dump stream (often referred to as a <quote>dump file</quote>
when stored as a file on disk) is a portable, flat file format
that describes the various revisions in your
repository—what was changed, by whom, when, and so on.
This dump stream is the primary mechanism used to marshal
versioned history—in whole or in part, with or without
modification—between repositories. And Subversion
provides the tools necessary for creating and loading these
dump streams: the <command>svnadmin dump</command> and
<command>svnadmin load</command> subcommands,
respectively.</para>
<warning>
<para>While the Subversion repository dump format contains
human-readable portions and a familiar structure (it
resembles an RFC 822 format, the same type of format used
for most email), it is <emphasis>not</emphasis> a plain-text
file format. It is a binary file format, highly sensitive
to meddling. For example, many text editors will corrupt
the file by automatically converting line endings.</para>
</warning>
<para>There are many reasons for dumping and loading Subversion
repository data. Early in Subversion's life, the most common
reason was due to the evolution of Subversion itself. As
Subversion matured, there were times when changes made to the
backend database schema caused compatibility issues with
previous versions of the repository, so users had to dump
their repository data using the previous version of
Subversion and load it into a freshly created repository with
the new version of Subversion. Now, these types of schema
changes haven't occurred since Subversion's 1.0 release, and
the Subversion developers promise not to force users to dump
and load their repositories when upgrading between minor
versions (such as from 1.3 to 1.4) of Subversion. But there
are still other reasons for dumping and loading, including
re-deploying a Berkeley DB repository on a new OS or CPU
architecture, switching between the Berkeley DB and FSFS
backends, or (as we'll cover later in this chapter in <xref
linkend="svn.reposadmin.maint.filtering" />) purging versioned
data from repository history.</para>
<note>
<para>The Subversion repository dump format describes
versioned repository changes only. It will not carry any
information about uncommitted transactions, user locks on
filesystem paths, repository or server configuration
customizations (including hook scripts), and so on.</para>
</note>
<para>Whatever your reason for migrating repository history,
using the <command>svnadmin dump</command> and
<command>svnadmin load</command> subcommands is
straightforward. <command>svnadmin dump</command> will output
a range of repository revisions that are formatted using
Subversion's custom filesystem dump format. The dump format
is printed to the standard output stream, while informative
messages are printed to the standard error stream. This
allows you to redirect the output stream to a file while
watching the status output in your terminal window. For
example:</para>
<screen>
$ svnlook youngest myrepos
26
$ svnadmin dump myrepos > dumpfile
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
…
* Dumped revision 25.
* Dumped revision 26.
</screen>
<para>At the end of the process, you will have a single file
(<filename>dumpfile</filename> in the previous example) that
contains all the data stored in your repository in the
requested range of revisions. Note that <command>svnadmin
dump</command> is reading revision trees from the repository
just like any other <quote>reader</quote> process would
(e.g., <command>svn checkout</command>), so it's safe
to run this command at any time.</para>
<para>The other subcommand in the pair, <command>svnadmin
load</command>, parses the standard input stream as a
Subversion repository dump file and effectively replays those
dumped revisions into the target repository for that
operation. It also gives informative feedback, this time
using the standard output stream:</para>
<screen>
$ svnadmin load newrepos < dumpfile
<<< Started new txn, based on original revision 1
* adding path : A ... done.
* adding path : A/B ... done.
…
------- Committed new rev 1 (loaded from original rev 1) >>>
<<< Started new txn, based on original revision 2
* editing path : A/mu ... done.
* editing path : A/D/G/rho ... done.
------- Committed new rev 2 (loaded from original rev 2) >>>
…
<<< Started new txn, based on original revision 25
* editing path : A/D/gamma ... done.
------- Committed new rev 25 (loaded from original rev 25) >>>
<<< Started new txn, based on original revision 26
* adding path : A/Z/zeta ... done.
* editing path : A/mu ... done.
------- Committed new rev 26 (loaded from original rev 26) >>>
</screen>
<para>The result of a load is new revisions added to a
repository—the same thing you get by making commits
against that repository from a regular Subversion client.
Just as in a commit, you can use hook programs to perform
actions before and after each of the commits made during a
load process. By passing the
<option>--use-pre-commit-hook</option> and
<option>--use-post-commit-hook</option> options to
<command>svnadmin load</command>, you can instruct Subversion
to execute the pre-commit and post-commit hook programs,
respectively, for each loaded revision. You might use these,
for example, to ensure that loaded revisions pass through the
same validation steps that regular commits pass through. Of
course, you should use these options with care—if your
post-commit hook sends emails to a mailing list for each new
commit, you might not want to spew hundreds or thousands of
commit emails in rapid succession at that list! You can read more about the use of hook
scripts in <xref
linkend="svn.reposadmin.create.hooks"/>.</para>
<para>Note that because <command>svnadmin</command> uses
standard input and output streams for the repository dump and
load processes, people who are feeling especially saucy can try
things such as this (perhaps even using different versions of
<command>svnadmin</command> on each side of the pipe):</para>
<screen>
$ svnadmin create newrepos
$ svnadmin dump oldrepos | svnadmin load newrepos
</screen>
<para>By default, the dump file will be quite large—much
larger than the repository itself. That's because by default
every version of every file is expressed as a full text in the
dump file. This is the fastest and simplest behavior, and
it's nice if you're piping the dump data directly into some other
process (such as a compression program, filtering program, or
loading process). But if you're creating a dump file
for longer-term storage, you'll likely want to save disk space
by using the <option>--deltas</option> option. With this
option, successive revisions of files will be output as
compressed, binary differences—just as file revisions
are stored in a repository. This option is slower, but it
results in a dump file much closer in size to the original
repository.</para>
<para>We mentioned previously that <command>svnadmin
dump</command> outputs a range of revisions. Use the
<option>--revision</option> (<option>-r</option>) option to
specify a single revision, or a range of revisions, to dump.
If you omit this option, all the existing repository revisions
will be dumped.</para>
<screen>
$ svnadmin dump myrepos -r 23 > rev-23.dumpfile
$ svnadmin dump myrepos -r 100:200 > revs-100-200.dumpfile
</screen>
<para>As Subversion dumps each new revision, it outputs only
enough information to allow a future loader to re-create that
revision based on the previous one. In other words, for any
given revision in the dump file, only the items that were
changed in that revision will appear in the dump. The only
exception to this rule is the first revision that is dumped
with the current <command>svnadmin dump</command>
command.</para>
<para>By default, Subversion will not express the first dumped
revision as merely differences to be applied to the previous
revision. For one thing, there is no previous revision in the
dump file! And second, Subversion cannot know the state of
the repository into which the dump data will be loaded (if it
ever is). To ensure that the output of each
execution of <command>svnadmin dump</command> is
self-sufficient, the first dumped revision is, by default, a
full representation of every directory, file, and property in
that revision of the repository.</para>
<para>However, you can change this default behavior. If you add
the <option>--incremental</option> option when you dump your
repository, <command>svnadmin</command> will compare the first
dumped revision against the previous revision in the
repository—the same way it treats every other revision that
gets dumped. It will then output the first revision exactly
as it does the rest of the revisions in the dump
range—mentioning only the changes that occurred in that
revision. The benefit of this is that you can create several
small dump files that can be loaded in succession, instead of
one large one, like so:</para>
<screen>
$ svnadmin dump myrepos -r 0:1000 > dumpfile1
$ svnadmin dump myrepos -r 1001:2000 --incremental > dumpfile2
$ svnadmin dump myrepos -r 2001:3000 --incremental > dumpfile3
</screen>
<para>These dump files could be loaded into a new repository
with the following command sequence:</para>
<screen>
$ svnadmin load newrepos < dumpfile1
$ svnadmin load newrepos < dumpfile2
$ svnadmin load newrepos < dumpfile3
</screen>
<para>Another neat trick you can perform with this
<option>--incremental</option> option involves appending to an
existing dump file a new range of dumped revisions. For
example, you might have a <literal>post-commit</literal> hook
that simply appends the repository dump of the single revision
that triggered the hook. Or you might have a script that runs
nightly to append dump file data for all the revisions that
were added to the repository since the last time the script
ran. Used like this, <command>svnadmin dump</command> can be
one way to back up changes to your repository over time in case
of a system crash or some other catastrophic event.</para>
<para>The dump format can also be used to merge the contents of
several different repositories into a single repository. By
using the <option>--parent-dir</option> option of
<command>svnadmin load</command>, you can specify a new
virtual root directory for the load process. That means if
you have dump files for three repositories—say
<filename>calc-dumpfile</filename>,
<filename>cal-dumpfile</filename>, and
<filename>ss-dumpfile</filename>—you can first create a new
repository to hold them all:</para>
<screen>
$ svnadmin create /var/svn/projects
$
</screen>
<para>Then, make new directories in the repository that will
encapsulate the contents of each of the three previous
repositories:</para>
<screen>
$ svn mkdir -m "Initial project roots" \
file:///var/svn/projects/calc \
file:///var/svn/projects/calendar \
file:///var/svn/projects/spreadsheet
Committed revision 1.
$
</screen>
<para>Lastly, load the individual dump files into their
respective locations in the new repository:</para>
<screen>
$ svnadmin load /var/svn/projects --parent-dir calc < calc-dumpfile
…
$ svnadmin load /var/svn/projects --parent-dir calendar < cal-dumpfile
…
$ svnadmin load /var/svn/projects --parent-dir spreadsheet < ss-dumpfile
…
$
</screen>
<para>We'll mention one final way to use the Subversion
repository dump format—conversion from a different
storage mechanism or version control system altogether.
Because the dump file format is, for the most part,
human-readable, it should be relatively easy to describe
generic sets of changes—each of which should be treated
as a new revision—using this file format. In fact, the
<command>cvs2svn</command> utility (see <xref
linkend="svn.forcvs.convert"/>) uses the dump format to
represent the contents of a CVS repository so that those
contents can be copied into a Subversion repository.</para>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.filtering">
<title>Filtering Repository History</title>
<para>Since Subversion stores your versioned history using, at
the very least, binary differencing algorithms and data
compression (optionally in a completely opaque database
system), attempting manual tweaks is unwise if not quite
difficult, and at any rate strongly discouraged. And once
data has been stored in your repository, Subversion
generally doesn't provide an easy way to remove that data.
<footnote>
<para>That's rather the reason you use version control at
all, right?</para>
</footnote>
But inevitably, there will be times when you would like to
manipulate the history of your repository. You might need
to strip out all instances of a file that was accidentally
added to the repository (and shouldn't be there for whatever
reason).
<footnote>
<para>Conscious, cautious removal of certain bits of
versioned data is actually supported by real use cases.
That's why an <quote>obliterate</quote> feature has been
one of the most highly requested Subversion features,
and one which the Subversion developers hope to soon
provide.</para>
</footnote>
Or, perhaps you have multiple projects sharing a
single repository, and you decide to split them up into
their own repositories. To accomplish tasks such as these,
administrators need a more manageable and malleable
representation of the data in their repositories—the
Subversion repository dump format.</para>
<para>As we described earlier in <xref
linkend="svn.reposadmin.maint.migrate" />, the Subversion
repository dump format is a human-readable representation of
the changes that you've made to your versioned data over time.
Use the <command>svnadmin dump</command> command to generate
the dump data, and <command>svnadmin load</command> to
populate a new repository with it. The great thing about the
human-readability aspect of the dump format is that, if you
aren't careless about it, you can manually inspect and modify
it. Of course, the downside is that if you have three years'
worth of repository activity encapsulated in what is likely to
be a very large dump file, it could take you a long, long time
to manually inspect and modify it.</para>
<para>That's where <command>svndumpfilter</command> becomes
useful. This program acts as a path-based filter for
repository dump streams. Simply give it either a list of
paths you wish to keep or a list of paths you wish to not
keep, and then pipe your repository dump data through this
filter. The result will be a modified stream of dump data
that contains only the versioned paths you (explicitly or
implicitly) requested.</para>
<para>Let's look at a realistic example of how you might use this
program. Earlier in this chapter (see <xref
linkend="svn.reposadmin.projects.chooselayout"/>), we discussed the
process of deciding how to choose a layout for the data in
your repositories—using one repository per project or
combining them, arranging stuff within your repository, and
so on. But sometimes after new revisions start flying in,
you rethink your layout and would like to make some changes.
A common change is the decision to move multiple projects
that are sharing a single repository into separate
repositories for each project.</para>
<para>Our imaginary repository contains three projects:
<literal>calc</literal>, <literal>calendar</literal>, and
<literal>spreadsheet</literal>. They have been living
side-by-side in a layout like this:</para>
<screen>
/
calc/
trunk/
branches/
tags/
calendar/
trunk/
branches/
tags/
spreadsheet/
trunk/
branches/
tags/
</screen>
<para>To get these three projects into their own repositories,
we first dump the whole repository:</para>
<screen>
$ svnadmin dump /var/svn/repos > repos-dumpfile
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
…
$
</screen>
<para>Next, run that dump file through the filter, each time
including only one of our top-level directories. This results
in three new dump files:</para>
<screen>
$ svndumpfilter include calc < repos-dumpfile > calc-dumpfile
…
$ svndumpfilter include calendar < repos-dumpfile > cal-dumpfile
…
$ svndumpfilter include spreadsheet < repos-dumpfile > ss-dumpfile
…
$
</screen>
<para>At this point, you have to make a decision. Each of your
dump files will create a valid repository, but will preserve
the paths exactly as they were in the original repository.
This means that even though you would have a repository solely
for your <literal>calc</literal> project, that repository
would still have a top-level directory named
<filename>calc</filename>. If you want your
<filename>trunk</filename>, <filename>tags</filename>, and
<filename>branches</filename> directories to live in the root
of your repository, you might wish to edit your dump files,
tweaking the <literal>Node-path</literal> and
<literal>Node-copyfrom-path</literal> headers so that they no
longer have that first <filename>calc/</filename> path
component. Also, you'll want to remove the section of dump
data that creates the <filename>calc</filename> directory. It
will look something like the following:</para>
<screen>
Node-path: calc
Node-action: add
Node-kind: dir
Content-length: 0
</screen>
<warning>
<para>If you do plan on manually editing the dump file to
remove a top-level directory, make sure your editor is
not set to automatically convert end-of-line characters to
the native format (e.g., <literal>\r\n</literal> to
<literal>\n</literal>), as the content will then not agree
with the metadata. This will render the dump file
useless.</para>
</warning>
<para>All that remains now is to create your three new
repositories, and load each dump file into the right
repository, ignoring the UUID found in the dump stream:</para>
<screen>
$ svnadmin create calc
$ svnadmin load --ignore-uuid calc < calc-dumpfile
<<< Started new transaction, based on original revision 1
* adding path : Makefile ... done.
* adding path : button.c ... done.
…
$ svnadmin create calendar
$ svnadmin load --ignore-uuid calendar < cal-dumpfile
<<< Started new transaction, based on original revision 1
* adding path : Makefile ... done.
* adding path : cal.c ... done.
…
$ svnadmin create spreadsheet
$ svnadmin load --ignore-uuid spreadsheet < ss-dumpfile
<<< Started new transaction, based on original revision 1
* adding path : Makefile ... done.
* adding path : ss.c ... done.
…
$
</screen>
<para>Both of <command>svndumpfilter</command>'s subcommands
accept options for deciding how to deal with
<quote>empty</quote> revisions. If a given revision
contains only changes to paths that were filtered out, that
now-empty revision could be considered uninteresting or even
unwanted. So to give the user control over what to do with
those revisions, <command>svndumpfilter</command> provides
the following command-line options:</para>
<variablelist>
<varlistentry>
<term><option>--drop-empty-revs</option></term>
<listitem>
<para>Do not generate empty revisions at all—just
omit them.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--renumber-revs</option></term>
<listitem>
<para>If empty revisions are dropped (using the
<option>--drop-empty-revs</option> option), change the
revision numbers of the remaining revisions so that
there are no gaps in the numeric sequence.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--preserve-revprops</option></term>
<listitem>
<para>If empty revisions are not dropped, preserve the
revision properties (log message, author, date, custom
properties, etc.) for those empty revisions.
Otherwise, empty revisions will contain only the
original datestamp, and a generated log message that
indicates that this revision was emptied by
<command>svndumpfilter</command>.</para>
</listitem>
</varlistentry>
</variablelist>
<para>While <command>svndumpfilter</command> can be very
useful and a huge timesaver, there are unfortunately a
couple of gotchas. First, this utility is overly sensitive
to path semantics. Pay attention to whether paths in your
dump file are specified with or without leading slashes.
You'll want to look at the <literal>Node-path</literal> and
<literal>Node-copyfrom-path</literal> headers.</para>
<screen>
…
Node-path: spreadsheet/Makefile
…
</screen>
<para>If the paths have leading slashes, you should
include leading slashes in the paths you pass to
<command>svndumpfilter include</command> and
<command>svndumpfilter exclude</command> (and if they don't,
you shouldn't). Further, if your dump file has an inconsistent
usage of leading slashes for some reason,
<footnote>
<para>While <command>svnadmin dump</command> has a
consistent leading slash policy (to not include
them), other programs that generate dump data might
not be so consistent.</para>
</footnote>
you should probably normalize those paths so that they all
have, or all lack, leading slashes.</para>
<para>Also, copied paths can give you some trouble.
Subversion supports copy operations in the repository, where
a new path is created by copying some already existing path.
It is possible that at some point in the lifetime of your
repository, you might have copied a file or directory from
some location that <command>svndumpfilter</command> is
excluding, to a location that it is including. To
make the dump data self-sufficient,
<command>svndumpfilter</command> needs to still show the
addition of the new path—including the contents of any
files created by the copy—and not represent that
addition as a copy from a source that won't exist in your
filtered dump data stream. But because the Subversion
repository dump format shows only what was changed in each
revision, the contents of the copy source might not be
readily available. If you suspect that you have any copies
of this sort in your repository, you might want to rethink
your set of included/excluded paths, perhaps including the
paths that served as sources of your troublesome copy
operations, too.</para>
<para>Finally, <command>svndumpfilter</command> takes path
filtering quite literally. If you are trying to copy the
history of a project rooted at
<filename>trunk/my-project</filename> and move it into a
repository of its own, you would, of course, use the
<command>svndumpfilter include</command> command to keep all
the changes in and under
<filename>trunk/my-project</filename>. But the resultant
dump file makes no assumptions about the repository into
which you plan to load this data. Specifically, the dump
data might begin with the revision that added the
<filename>trunk/my-project</filename> directory, but it will
<emphasis>not</emphasis> contain directives that would
create the <filename>trunk</filename> directory itself
(because <filename>trunk</filename> doesn't match the
include filter). You'll need to make sure that any
directories that the new dump stream expects to exist
actually do exist in the target repository before trying to
load the stream into that repository.</para>
</sect2>
<!-- =============================================================== -->
<sect2 id="svn.reposadmin.maint.replication">
<title>Repository Replication</title>
<para>There are several scenarios in which it is quite handy to
have a Subversion repository whose version history is exactly
the same as some other repository's. Perhaps the most obvious
one is the maintenance of a simple backup repository, used
when the primary repository has become inaccessible due to a
hardware failure, network outage, or other such annoyance.
Other scenarios include deploying mirror repositories to
distribute heavy Subversion load across multiple servers, use
as a soft-upgrade mechanism, and so on.</para>
<para>As of version 1.4, Subversion provides a program for
managing scenarios such as
these—<command>svnsync</command>. This works by
essentially asking the Subversion server to
<quote>replay</quote> revisions, one at a time. It then uses
that revision information to mimic a commit of the same to
another repository. Neither repository needs to be locally
accessible to the machine on which <command>svnsync</command> is
running—its parameters are repository URLs, and it does
all its work through Subversion's Repository Access (RA)
interfaces. All it requires is read access to the source
repository and read/write access to the destination
repository.</para>
<note>
<para>When using <command>svnsync</command> against a remote
source repository, the Subversion server for that repository
must be running Subversion version 1.4 or later.</para>
</note>
<para>Assuming you already have a source repository that you'd
like to mirror, the next thing you need is an empty target
repository that will actually serve as that mirror. This
target repository can use either of the available filesystem
data-store backends (see <xref
linkend="svn.reposadmin.basics.backends" />), but it must not
yet have any version history in it. The protocol that
<command>svnsync</command> uses to communicate revision information
is highly sensitive to mismatches between the versioned
histories contained in the source and target repositories.
For this reason, while <command>svnsync</command> cannot
<emphasis>demand</emphasis> that the target repository be
read-only,
<footnote>
<para>In fact, it can't truly be read-only, or
<command>svnsync</command> itself would have a tough time
copying revision history into it.</para>
</footnote>
allowing the revision history in the target repository to
change by any mechanism other than the mirroring process is a
recipe for disaster.</para>
<warning>
<para>Do <emphasis>not</emphasis> modify a mirror repository
in such a way as to cause its version history to deviate
from that of the repository it mirrors. The only commits
and revision property modifications that ever occur on that
mirror repository should be those performed by the
<command>svnsync</command> tool.</para>
</warning>
<para>Another requirement of the target repository is that the
<command>svnsync</command> process be allowed to modify
revision properties. Because <command>svnsync</command> works
within the framework of that repository's hook system, the
default state of the repository (which is to disallow revision
property changes; see <xref
linkend="svn.ref.reposhooks.pre-revprop-change" />) is
insufficient. You'll need to explicitly implement the
pre-revprop-change hook, and your script must allow
<command>svnsync</command> to set and change revision
properties. With those provisions in place, you are ready to
start mirroring repository revisions.</para>
<tip>
<para>It's a good idea to implement authorization measures
that allow your repository replication process to perform
its tasks while preventing other users from modifying the
contents of your mirror repository at all.</para>
</tip>
<para>Let's walk through the use of <command>svnsync</command>
in a somewhat typical mirroring scenario. We'll pepper this
discourse with practical recommendations, which you are free to
disregard if they aren't required by or suitable for your
environment.</para>
<para>As a service to the fine developers of our favorite
version control system, we will be mirroring the public
Subversion source code repository and exposing that mirror
publicly on the Internet, hosted on a different machine than
the one on which the original Subversion source code
repository lives. This remote host has a global configuration
that permits anonymous users to read the contents of
repositories on the host, but requires users to authenticate
to modify those repositories. (Please forgive us for
glossing over the details of Subversion server configuration
for the moment—those are covered thoroughly in <xref
linkend="svn.serverconfig" />.) And for no other reason than
that it makes for a more interesting example, we'll be driving
the replication process from a third machine—the one that
we currently find ourselves using.</para>
<para>First, we'll create the repository which will be our
mirror. This and the next couple of steps do require shell
access to the machine on which the mirror repository will
live. Once the repository is all configured, though, we
shouldn't need to touch it directly again.</para>
<screen>
$ ssh admin@svn.example.com \
"svnadmin create /var/svn/svn-mirror"
admin@svn.example.com's password: ********
$
</screen>
<para>At this point, we have our repository, and due to our
server's configuration, that repository is now
<quote>live</quote> on the Internet. Now, because we don't
want anything modifying the repository except our replication
process, we need a way to distinguish that process from other
would-be committers. To do so, we use a dedicated username
for our process. Only commits and revision property
modifications performed by the special username
<literal>syncuser</literal> will be allowed.</para>
<para>We'll use the repository's hook system both to allow the
replication process to do what it needs to do and to enforce
that only it is doing those things. We accomplish this by
implementing two of the repository event
hooks—pre-revprop-change and start-commit. Our
<filename>pre-revprop-change</filename> hook script is found
in <xref
linkend="svn.reposadmin.maint.replication.pre-revprop-change"
/>, and basically verifies that the user attempting the
property changes is our <literal>syncuser</literal> user. If
so, the change is allowed; otherwise, it is denied.</para>
<example id="svn.reposadmin.maint.replication.pre-revprop-change">
<title>Mirror repository's pre-revprop-change hook script</title>
<programlisting>
#!/bin/sh
USER="$3"
if [ "$USER" = "syncuser" ]; then exit 0; fi
echo "Only the syncuser user may change revision properties" >&2
exit 1
</programlisting>
</example>
<para>That covers revision property changes. Now we need to
ensure that only the <literal>syncuser</literal> user is
permitted to commit new revisions to the repository. We do
this using a <filename>start-commit</filename> hook scripts
such as the one in <xref
linkend="svn.reposadmin.maint.replication.start-commit"
/>.</para>
<example id="svn.reposadmin.maint.replication.start-commit">
<title>Mirror repository's start-commit hook script</title>
<programlisting>
#!/bin/sh
USER="$2"
if [ "$USER" = "syncuser" ]; then exit 0; fi
echo "Only the syncuser user may commit new revisions" >&2
exit 1
</programlisting>
</example>
<para>After installing our hook scripts and ensuring that they
are executable by the Subversion server, we're finished with
the setup of the mirror repository. Now, we get to actually
do the mirroring.</para>
<para>The first thing we need to do with
<command>svnsync</command> is to register in our target
repository the fact that it will be a mirror of the source
repository. We do this using the <command>svnsync
initialize</command> subcommand. The URLs we provide point to
the root directories of the target and source repositories,
respectively. In Subversion 1.4, this is required—only
full mirroring of repositories is permitted. In Subversion
1.5, though, you can use <command>svnsync</command> to mirror
only some subtree of the repository, too.</para>
<screen>
$ svnsync help init
initialize (init): usage: svnsync initialize DEST_URL SOURCE_URL
Initialize a destination repository for synchronization from
another repository.
…
$ svnsync initialize http://svn.example.com/svn-mirror \
http://svn.collab.net/repos/svn \
--sync-username syncuser --sync-password syncpass
Copied properties for revision 0.
$
</screen>
<para>Our target repository will now remember that it is a
mirror of the public Subversion source code repository.
Notice that we provided a username and password as arguments
to <command>svnsync</command>—that was required by the
pre-revprop-change hook on our mirror repository.</para>
<note>
<para>In Subversion 1.4, the values given to
<command>svnsync</command>'s <option>--username</option> and
<option>--password</option> command-line options were used
for authentication against both the source and destination
repositories. This caused problems when a user's
credentials weren't exactly the same for both repositories,
especially when running in noninteractive mode (with the
<option>--non-interac