1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head xmlns="http://www.w3.org/1999/xhtml">
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title xmlns="">Archive Rotation</title>
7
<link rel="stylesheet" href="../../libs/ubuntu-book.css" type="text/css" />
8
<link rel="home" href="index.html" title="Ubuntu Server Guide" />
9
<link rel="up" href="backups.html" title="Chapter 18. Backups" />
10
<link rel="prev" href="backup-shellscripts.html" title="Shell Scripts" />
11
<link rel="next" href="bacula.html" title="Bacula" />
12
<link rel="copyright" href="legal.html" title="Credits and License" />
16
<img id="topcap" alt="" src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png" />
17
<div id="layout" class="container clear-block">
18
<script xmlns="" src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"></script>
19
<script xmlns="" type="text/javascript">
20
_uacct = "UA-1018242-8";
24
<div id="logo-floater">
26
<a href="https://help.ubuntu.com" title="Ubuntu Documentation">
27
<img alt="Ubuntu" id="logo" src="https://help.ubuntu.com/htdocs/ubuntunew/img/logo.png" />
32
<form action="http://www.google.com/cse" id="cse-search-box">
34
<input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />
35
<input type="hidden" name="ie" value="UTF-8" />
36
<input type="text" name="q" size="27" />
37
<input type="submit" name="sa" value="Search" />
42
document.write('<form action="https://help.ubuntu.com/search.html" id="cse-search-box">');
43
document.write(' <div>');
44
document.write(' <input type="hidden" name="cof" value="FORID:9" />');
45
document.write(' <input type="hidden" name="cx" value="003883529982892832976:e2vwumte3fq" />');
46
document.write(' <input type="hidden" name="ie" value="UTF-8" />');
47
document.write(' <input type="text" name="q" size="27" />');
48
document.write(' <input type="submit" name="sa" value="Search" />');
49
document.write(' </div>');
50
document.write('</form>');
53
<a href="https://help.ubuntu.com/">
54
<img alt="Official Documentation" src="https://help.ubuntu.com/htdocs/ubuntunew/img/help-about.png" />
55
<span>Official Documentation</span>
61
<div class="breadcrumbs"><a href="https://help.ubuntu.com/">Ubuntu Documentation</a> > <a href="https://help.ubuntu.com/11.04">Ubuntu 11.04</a> > <span class="breadcrumb-link"><a href="index.html">Ubuntu Server Guide</a></span> > <span class="breadcrumb-link"><a href="backups.html">Backups</a></span> > <span class="breadcrumb-node">Archive Rotation</span></div>
62
<div xmlns="http://www.w3.org/1999/xhtml" class="sect1" title="Archive Rotation">
63
<div class="titlepage">
66
<h2 class="title" style="clear: both"><a id="backups-shellscripts-rotation"></a>Archive Rotation</h2>
71
The shell script in section <a class="xref" href="backup-shellscripts.html" title="Shell Scripts">the section called “Shell Scripts”</a> only allows for seven different archives. For
72
a server whose data doesn't change often this may be enough. If the server has a large amount of data a more
73
robust rotation scheme should be used.
75
<div class="sect2" title="Rotating NFS Archives">
76
<div class="titlepage">
79
<h3 class="title"><a id="backups-nfs-rotation"></a>Rotating NFS Archives</h3>
84
In this section the shell script will be slightly modified to implement a grandfather-father-son rotation scheme
85
(monthly-weekly-daily):
87
<div class="itemizedlist">
88
<ul class="itemizedlist" type="disc">
91
The rotation will do a <span class="emphasis"><em>daily</em></span> backup Sunday through Friday.
96
On Saturday a <span class="emphasis"><em>weekly</em></span> backup is done giving you four weekly backups a month.
101
The <span class="emphasis"><em>monthly</em></span> backup is done on the first of the month rotating two monthly backups based
102
on if the month is odd or even.
108
Here is the new script:
110
<pre class="programlisting">
112
####################################
114
# Backup to NFS mount script with
115
# grandfather-father-son rotation.
117
####################################
120
backup_files="/home /var/spool/mail /etc /root /boot /opt"
122
# Where to backup to.
125
# Setup variables for the archive filename.
127
hostname=$(hostname -s)
129
# Find which week of the month 1-4 it is.
131
if (( $day_num <= 7 )); then
132
week_file="$hostname-week1.tgz"
133
elif (( $day_num > 7 && $day_num <= 14 )); then
134
week_file="$hostname-week2.tgz"
135
elif (( $day_num > 14 && $day_num <= 21 )); then
136
week_file="$hostname-week3.tgz"
137
elif (( $day_num > 21 && $day_num < 32 )); then
138
week_file="$hostname-week4.tgz"
141
# Find if the Month is odd or even.
142
month_num=$(date +%m)
143
month=$(expr $month_num % 2)
144
if [ $month -eq 0 ]; then
145
month_file="$hostname-month2.tgz"
147
month_file="$hostname-month1.tgz"
150
# Create archive filename.
151
if [ $day_num == 1 ]; then
152
archive_file=$month_file
153
elif [ $day != "Saturday" ]; then
154
archive_file="$hostname-$day.tgz"
156
archive_file=$week_file
159
# Print start status message.
160
echo "Backing up $backup_files to $dest/$archive_file"
164
# Backup the files using tar.
165
tar czf $dest/$archive_file $backup_files
167
# Print end status message.
169
echo "Backup finished"
172
# Long listing of files in $dest to check file sizes.
176
The script can be executed using the same methods as in <a class="xref" href="backup-shellscripts.html#backup-executing-shellscript" title="Executing the Script">the section called “Executing the Script”</a>.
179
It is good practice to take backup media off site in case of a disaster. In the shell script example the backup
180
media is another server providing an NFS share. In all likelihood taking the NFS server to another location would not
182
Depending upon connection speeds it may be an option to copy the archive file over a WAN link to a server in another location.
185
Another option is to copy the archive file to an external hard drive which can then be taken off site.
186
Since the price of external hard drives continue to decrease it may be cost-effective to use two drives for each archive level.
187
This would allow you to have one external drive attached to the backup server and one in another location.
190
<div class="sect2" title="Tape Drives">
191
<div class="titlepage">
194
<h3 class="title"><a id="backup-shellscript-tapedrive"></a>Tape Drives</h3>
199
A tape drive attached to the server can be used instead of a NFS share. Using a tape drive simplifies archive rotation, and
200
taking the media off site as well.
203
When using a tape drive the filename portions of the script aren't needed because the date is sent directly to the tape device.
204
Some commands to manipulate the tape are needed. This is accomplished using <span class="application"><strong>mt</strong></span>, a magnetic tape
205
control utility part of the <span class="application"><strong>cpio</strong></span> package.
208
Here is the shell script modified to use a tape drive:
210
<pre class="programlisting">
212
####################################
214
# Backup to tape drive script.
216
####################################
219
backup_files="/home /var/spool/mail /etc /root /boot /opt"
221
# Where to backup to.
224
# Print start status message.
225
echo "Backing up $backup_files to $dest"
229
# Make sure the tape is rewound.
232
# Backup the files using tar.
233
tar czf $dest $backup_files
235
# Rewind and eject the tape.
238
# Print end status message.
240
echo "Backup finished"
243
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
244
<table border="0" summary="Note">
246
<td rowspan="2" align="center" valign="top" width="25">
247
<img alt="[Note]" src="../../libs/admon/note.png" />
249
<th align="left"></th>
252
<td align="left" valign="top">
254
The default device name for a SCSI tape drive is <code class="filename">/dev/st0</code>. Use the appropriate device path for your
262
Restoring from a tape drive is basically the same as restoring from a file. Simply rewind the tape and use the device path
263
instead of a file path. For example to restore the <code class="filename">/etc/hosts</code> file to <code class="filename">/tmp/etc/hosts</code>:
266
<span class="command"><strong>mt -f /dev/st0 rewind</strong></span>
267
<span class="command"><strong>tar -xzf /dev/st0 -C /tmp etc/hosts</strong></span>
272
<div xmlns="http://www.w3.org/1999/xhtml" class="navfooter">
274
<table width="100%" summary="Navigation footer">
276
<td width="40%" align="left"><a accesskey="p" href="backup-shellscripts.html"><img src="../../libs/navig/prev.png" alt="Prev" /></a> </td>
277
<td width="20%" align="center">
278
<a accesskey="u" href="backups.html">
279
<img src="../../libs/navig/up.png" alt="Up" />
282
<td width="40%" align="right"> <a accesskey="n" href="bacula.html"><img src="../../libs/navig/next.png" alt="Next" /></a></td>
285
<td width="40%" align="left" valign="top">Shell Scripts </td>
286
<td width="20%" align="center">
287
<a accesskey="h" href="index.html">
288
<img src="../../libs/navig/home.png" alt="Home" />
291
<td width="40%" align="right" valign="top"> Bacula</td>
297
<div id="ubuntulinks">
298
<p>The material in this document is available under a free license, see <a href="/legal.html">Legal</a> for details<br />
299
For information on contributing see the <a href="https://wiki.ubuntu.com/DocumentationTeam">Ubuntu Documentation Team wiki page</a>. To report a problem, visit the <a href="https://bugs.launchpad.net/ubuntu/+source/ubuntu-docs">bug page for Ubuntu Documentation</a></p>
303
<img src="https://help.ubuntu.com/htdocs/ubuntunew/img/cap-bottom.png" alt="" />