<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EZ Linux Admin &#187; Linux Back Up</title>
	<atom:link href="http://www.ezlinuxadmin.com/category/linux-back-up/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ezlinuxadmin.com</link>
	<description>Making Linux Easier</description>
	<lastBuildDate>Tue, 29 Jun 2010 19:37:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux rescue CD</title>
		<link>http://www.ezlinuxadmin.com/2009/09/linux-rescue-cd/</link>
		<comments>http://www.ezlinuxadmin.com/2009/09/linux-rescue-cd/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 01:41:27 +0000</pubDate>
		<dc:creator>EZ linux</dc:creator>
				<category><![CDATA[Linux Back Up]]></category>
		<category><![CDATA[Linux Software / Scripts]]></category>
		<category><![CDATA[Linux Tricks]]></category>
		<category><![CDATA[Linux rescue CD]]></category>
		<category><![CDATA[Sysresccd]]></category>

		<guid isPermaLink="false">http://www.ezlinuxadmin.com/?p=300</guid>
		<description><![CDATA[
SystemRescueCd is a Linux system rescue disk available as a bootable CD-ROM or USB stick for administrating or repairing your system and data after a crash. It aims to provide an easy way to carry out admin tasks on your computer, such as creating and editing the partitions of the hard disk. It comes with [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-301" href="http://www.ezlinuxadmin.com/2009/09/linux-rescue-cd/rescue/"><img class="alignnone size-medium wp-image-301" title="rescue" src="http://www.ezlinuxadmin.com/wp-content/uploads/2009/09/rescue-300x277.jpg" alt="rescue" width="300" height="277" /></a></p>
<p>SystemRescueCd is a Linux system rescue disk available as a bootable CD-ROM or USB stick for administrating or repairing your system and data after a crash. It aims to provide an easy way to carry out admin tasks on your computer, such as creating and editing the partitions of the hard disk. It comes with a lot of linux software such as system tools (parted, partimage, fstools, &#8230;) and basic tools (editors, midnight commander, network tools). It requires no installation since you just have to boot on the CD-ROM. It can be used to perform admin tasks on both linux servers, linux desktops or windows boxes. The kernel supports most of the important file systems (ext2/ext3/ext4, reiserfs, reiser4, btrfs, xfs, jfs, vfat, ntfs, iso9660), as well as network filesystems (samba and nfs).</p>
<p><img src="file:///C:/Users/dwhs/AppData/Local/Temp/moz-screenshot.png" alt="" /><img src="file:///C:/Users/dwhs/AppData/Local/Temp/moz-screenshot-1.png" alt="" /><img src="file:///C:/Users/dwhs/AppData/Local/Temp/moz-screenshot-2.png" alt="" /><a href="http://www.ezlinuxadmin.com/wp-content/uploads/2009/09/arrow.gif"><img class="alignnone size-full wp-image-387" title="arrow" src="http://www.ezlinuxadmin.com/wp-content/uploads/2009/09/arrow.gif" alt="" width="42" height="41" /></a><strong>Download the <a href="http://www.sysresccd.org/Download">Linux Rescue Disk</a> Here</strong></p>
<p><a href="http://www.sysresccd.org/Main_Page">http://www.sysresccd.org/Main_Page</a></p>
<p><strong><img class="alignnone size-full wp-image-387" title="arrow" src="http://www.ezlinuxadmin.com/wp-content/uploads/2009/09/arrow.gif" alt="" width="42" height="41" />Booting from SystemRescueCd</strong></p>
<p>A successfully boot of SystemRescueCd presents the first screen with SystemRescueCd written in ASCII art.</p>
<p>Press F2/F3/F4/F5/F6 and read advanced boot instructions.</p>
<p>Press Enter to boot with the default options.</p>
<p>There are two parts in the boot command: &lt;boot-image&gt; &lt;boot-options&gt;. For example you may want to boot with rescue64 as boot-image and docache setkmap=uk as boot-options. Use spaces between options. Additional options are at Booting the CD-ROM<br />
Main boot images</p>
<p>There are four main boot images with SystemRescueCd. The differences are detailed in the kernel page</p>
<p>* rescuecd The default for 32bit systems, with Framebuffer disabled.<br />
* altker32 This is an alternative kernel for 32bit systems. Boot this kernel if you have problems with rescuecd. altker32 was named vmlinuz2</p>
<p>* rescue64 Default 64 bit kernel. Use it if you want to chroot to a 64bit linux system installed on your hard disk, or to run 64 bit programs. This kernel is able to boot SystemRescueCd from the cdrom with 32bit programs, and requires a processor with 64bit instructions (amd64 / em64t).<br />
* altker64 This is an alternative kernel for 64bit systems. Boot with this kernel in case you have problems with rescue64.</p>
<p>Main boot options</p>
<p>Here are the most important boot options:</p>
<p>* docache: copy all the files it needs to RAM . This permits the sysrescuecd to be ejected and insert another disc in the drive. The system runs faster. Requires at least 256MB of memory.<br />
* setkmap=cc: During the boot process, the system asks for the kind of keyboard. Use this option to avoid that question. Replace &#8216;cc&#8217; with the keyboard you have: &#8216;us&#8217; for USA, &#8216;uk&#8217; for british, &#8216;de&#8217; for german, &#8230;<br />
* root=/dev/idxn: the root=&lt;device&gt; option boots an existing linux system. For example, if you have a linux Gentoo installed on /dev/sda6 , type rescuecd root=/dev/sda6 and Gentoo Linux will be started instead of the system on the CD. Use a 64bit kernel if your system has 64bit programs. For instance, you can boot a 64bit linux system installed on /dev/sda6 with rescue64 root=/dev/sda6. From SystemRescueCd-1.0.4, this option works with LVM disks, so you can use something like rescuecd root=/dev/VolGroup00/LogVol00. root=auto will scan the block devices of the computer to find a linux system. The first linux system found on the disks will be started. This allows starting the system from the CD in the event there is a problem with your boot loader or with your installed nkernel . See for more details.<br />
* ide=nodma or all-generic-ide: use these options if there is a problem related to the hard disk, for instance if the kernel boot process hangs on a driver related to the storage.<br />
* doxdetect or forcevesa: use these options if you cannot get the graphical environment to work when you type startx in the shell prompt.<br />
* acpi-off / noapic / irqpool: use these options if you have any problem when the kernel boots: if it hangs on a driver or if it crashes, &#8230;</p>
<p>Additional Programs</p>
<p>* Some programs included are normally booted from their own floppy. Press F2 to display the list of the these floppy disk images. For instance memtest runs an extensive memory test. ntpass allows you to change the password of any windows user accounts including the administrator account.</p>
<p>Working in the console mode</p>
<p>Mount partitions in order to troubleshoot a Linux or a Windows system installed on your disk. You can mount linux filesystems (ext2fs, ext3fs, reiserfs, reiser4, jfs, xfs) You can backup/restore data or operating system files.</p>
<p>Midnight Commander (type mc )is able to copy/move/delete/edit files and directories. The vim and qemacs editors can be used to edit files.</p>
<p>Six virtual consoles are available. Press Alt+F1 for the first virtual console, Alt+F2 for the second one, &#8230;</p>
<p>Working in the graphical environment</p>
<p>If you need graphical tools (such as GParted) start the graphical environment by typing wizard . There are two graphical environments: Xorg and Xvesa. You should try Xorg first. If Xorg fails to start, run wizard again and choose Xvesa which should always work. The graphical environment allows you to work with GParted (partition manager), to use graphical editors (Geany or GVim), to browse the web with Firefox and use terminals like xfce-terminal or mrxvt.</p>
<p>Setting up your network</p>
<p>With SystemRescueCd you can use the network. It&#8217;s useful to make a backup over the network, download files, work remotely using ssh, telnet or access files that are shared on a Unix server (with NFS)</p>
<p>The most convenient way to configure your network is to type net-setup at shell prompt. You can also use the following command lines to configure a network interface by hand:</p>
<p>If your system has supported hardware, the network interface card (NIC) was auto-detected, and the driver loaded. The interface needs to be assigned an IP address and a default gateway. To use use dynamic configuration, dhcpcd eth0. Use ifconfig -a to display the IP address the DHCP server leased to the interface. To assign a specific static IP address, enter ifconfig eth0 192.168.10.17 . Next the default route is configured. For example, for an interface at address 192.168.10.17 connected to a gateway at 192.168.10.2 enter: route add default gw 192.168.10.2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ezlinuxadmin.com/2009/09/linux-rescue-cd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux back ups</title>
		<link>http://www.ezlinuxadmin.com/2008/07/linux-back-ups/</link>
		<comments>http://www.ezlinuxadmin.com/2008/07/linux-back-ups/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 22:48:28 +0000</pubDate>
		<dc:creator>EZ linux</dc:creator>
				<category><![CDATA[Linux Back Up]]></category>

		<guid isPermaLink="false">http://www.ezlinuxadmin.com/?p=86</guid>
		<description><![CDATA[
If you use Linux, you already have access to extremely powerful tools for creating custom backup solutions. The solutions in this article can help you perform simple to more advanced and secure network backups using open source tools that are part of nearly every Linux distribution.
Simple backups
This article follows a step-by-step approach that is quite [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ezlinuxadmin.com/wp-content/uploads/2008/07/moonwalk.jpg" title="moon walk"><img src="http://www.ezlinuxadmin.com/wp-content/uploads/2008/07/moonwalk.jpg" alt="moon walk" /></a></p>
<p>If you use Linux, you already have access to extremely powerful tools for creating custom backup solutions. The solutions in this article can help you perform simple to more advanced and secure network backups using open source tools that are part of nearly every Linux distribution.</p>
<p>Simple backups</p>
<p>This article follows a step-by-step approach that is quite straightforward once you follow the basic steps.</p>
<p>Let&#8217;s begin with a simple, yet powerful archive mechanism on our way to a more advanced distributed backup solution. Let&#8217;s examine a handy script called arc, which will allow us to create backup snapshots from a Linux shell prompt.</p>
<p>Listing 1. The arc shell script</p>
<p>#!/bin/sh<br />
tar czvf $1.$(date +%Y%m%d-%H%M%S).tgz $1<br />
exit $?</p>
<p>The arc script accepts a single file or directory name as a parameter and creates a compressed archive file with the current date embedded into the resulting archive file&#8217;s name. For example, if you have a directory called beoserver, you can invoke the arc script, passing it the beoserver directory name to create a compressed archive such as: beoserver.20040321-014844.tgz</p>
<p>The use of the date command to embed a date and timestamp helps to organize your archived files. The date format is Year, Month, Day, Hour, Minutes, and Seconds &#8212; although the use of the seconds field is perhaps a bit much. View the man page for the date command (man date) to learn about other options. Also, in Listing 1, we pass the -v (verbose) option to tar. This causes tar to display all of the files it&#8217;s archiving. Remove the -v option if you&#8217;d like the backup to proceed silently.</p>
<p>Listing 2. Archiving the beoserver directory</p>
<p>$ ls<br />
arc  beoserver<br />
$ ./arc beoserver<br />
beoserver/<br />
beoserver/bookl.dat<br />
beoserver/beoserver_ab_off<br />
beoserver/beoserver_ab_on<br />
$ ls<br />
arc  beoserver  beoserver.20040321-014844.tgz</p>
<p>Advanced backups</p>
<p>This simple backup example is useful; however, it still includes a manual backup process. The industry&#8217;s best practices recommend backing up often, onto multiple media, and to separate geographic locations. The central idea is to avoid relying entirely on any single storage media or single location.</p>
<p>We&#8217;ll tackle this challenge in our next example, where we&#8217;ll examine a fictitious distributed network, illustrated in Figure 1, which shows a system administrator with access to two remote servers and an offsite data storage server.</p>
<p>Figure 1. Distributed network</p>
<p>The backup files on Server #1 and #2 will be securely transmitted to the offsite storage server, and the entire distributed backup process will occur on a regular basis without human intervention. We&#8217;ll use a set of standard tools that are part of the Open Secure Shell tool suite (OpenSSH), as well as the tape archiver (tar), and the cron task scheduling service. Our overall plan will be to use cron for scheduling, shell programming and the tar application during the backup process, OpenSSH secure shell (ssh) encryption for remote access, and authentication, and secure shell copy (scp) to automate file transfers. Be sure to review each tool&#8217;s man page for additional information.</p>
<p>Secure remote access using public/private keys</p>
<p>In the context of digital security, a key is a piece of data which is used to encrypt or decrypt other pieces of data. The public and private key scheme is interesting because data encrypted with a public key can only be decrypted with the associated private key. You may freely distribute a public key so that others can encrypt the messages they send you. One of the reasons that public/private key schemes have revolutionized digital security is because the sender and receiver don&#8217;t have to share a common password. Among other things, public/private key cryptography has made e-commerce and other secure transactions possible. In this article, we&#8217;ll create and use public and private keys to create a highly secure distributed backup solution.</p>
<p>Each machine involved in the backup process must be running the OpenSSH secure shell service (sshd) with port 22 accessible through any intermediate firewall. If you access remote servers, then there is a good chance you&#8217;re already using secure shell.</p>
<p>Our goal will be to provide machines with secure access without requiring the need to manually provide passwords. Some people think that the easiest way to do this is to set up password-less access: do not do this. It is not secure. Instead, the approach we&#8217;ll use in this article will take perhaps an hour of your time, set up a system which gives all the convenience of &#8220;passphraseless&#8221; accounts &#8212; but is recognized as being highly secure.</p>
<p>Let&#8217;s begin by ensuring that OpenSSH is installed and proceed to check its version number. At the time this article was written, the latest OpenSSH release was version 3.8, released on February 24, 2004. You should consider using a recent and stable release, and at the very least use a release which is newer than version 2.x. Visit the OpenSSH Security page for details regarding older version-specific vulnerabilities (see the link in Resources later in this article). At this point in time, OpenSSH is quite stable and has proven to be immune to many of the vulnerabilities which have been reported for other SSH tools.</p>
<p>At a shell prompt, type ssh with the capital V option to check the version number:</p>
<p>$ ssh -V<br />
OpenSSH_3.5p1, SSH protocols 1.5/2.0, OpenSSL 0&#215;0090701f</p>
<p>If ssh returns a version number greater than 2.x, the machine is in relatively good shape. However, it is recommended that you use the latest stable releases of all software, and this is especially important for security-related software.</p>
<p>Our first step is to log in to the offsite storage server machine using the account, which will have the privilege of being able to access servers 1 and 2 (see Figure 1).</p>
<p>$ ssh accountname@somedomain.com</p>
<p>Once logged on to the offsite storage machine, use the ssh-keygen program to create a public/private key pair using the -t dsa option. The -t option is required, and is used to specify the type of encryption key we&#8217;re interested in generating. We&#8217;ll use the Digital Signature Algorithm (DSA), which will enable us to use the newer SSH2 protocol. See the ssh-keygen man page for more details.</p>
<p>During the execution of ssh-keygen, you&#8217;ll be prompted for the location where the ssh keys will be stored before you&#8217;re asked for a passphrase. Simply press enter when asked where to save the key and the ssh-keygen program will create a hidden directory called .ssh (if one doesn&#8217;t already exist) along with two files, a public and private key file.</p>
<p>An interesting feature of ssh-keygen is that it will allow you to simply press enter when prompted for a passphrase. If you don&#8217;t supply a passphrase, then ssh-keygen will generate keys which are not encrypted! As you can imagine, this isn&#8217;t a good idea. When asked for a passphrase, make sure to enter a reasonably long string message which contains alphanumeric characters rather than a simple password string.</p>
<p>Listing 3. Always choose a good passphrase</p>
<p>[offsite]:$ ssh-keygen -t dsa<br />
Generating public/private dsa key pair.<br />
Enter file in which to save the key (/home/accountname/.ssh/id_dsa):<br />
Enter passphrase (empty for no passphrase): (enter passphrase)<br />
Enter same passphrase again: (enter passphrase)<br />
Your identification has been saved in /home/accountname/.ssh/id_dsa.<br />
Your public key has been saved in /home/accountname/.ssh/id_dsa.pub.<br />
The key fingerprint is:<br />
7e:5e:b2:f2:d4:54:58:6a:fa:6b:52:9c:da:a8:53:1b accountname@offsite</p>
<p>Because the .ssh directory which ssh-keygen creates is a hidden &#8220;dot&#8221; directory, pass the -a option to the ls command to view the newly created directory:</p>
<p>[offsite]$ ls -a<br />
. .. .bash_logout .bash_profile .bashrc .emacs .gtkrc .ssh</p>
<p>Enter the hidden .ssh directory and list the contents:</p>
<p>[offsite]$ cd .ssh<br />
[offsite]$ ls -lrt<br />
id_dsa id_dsa.pub</p>
<p>We now have a private key (id_dsa) and a public key (id_dsa.pub) in the hidden .ssh directory. You can examine the contents of each key file using a text editor such as vi or emacs, or simply by using the less or cat commands. You&#8217;ll notice that the contents consist of alphanumeric characters encoded in base64.</p>
<p>Next, we need to copy and install the public key on servers 1 and 2. Do not use ftp. Rather, use the secure copy program to transmit the public keys onto each of the remote machines:</p>
<p>Listing 4. Installing the public keys on the remote servers</p>
<p>[offsite]$ scp .ssh/id_dsa.pub accountname@server1.com:offsite.pub<br />
accountname@server1.com&#8217;s password: (enter password, not new<br />
passphrase!)<br />
id_dsa.pub 100% |*****************************| 614 00:00</p>
<p>[offsite]$ scp .ssh/id_dsa.pub accountname@server2.com:offsite.pub<br />
accountname@server2.com&#8217;s password: (enter password, not new<br />
passphrase!)<br />
id_dsa.pub 100% |*****************************| 614 00:00</p>
<p>After we install the new public keys, we&#8217;ll be able to sign on to each machine using the passphrase we specified when creating the private and public keys. For now, log in to each machine and append the contents of the offsite.pub file to a file called authorized_keys, which is stored in each remote machine&#8217;s .ssh directory. We can use a text editor or simply use the cat command to append the offsite.pub file&#8217;s contents onto the authorized_keys file:</p>
<p>Listing 5. Add offsite.pub to your list of authorized keys</p>
<p>[offsite]$ ssh accountname@server1.com<br />
accountname@server1.com&#8217;s password: (enter password, not new<br />
passphrase!)<br />
[server1]$ cat offsite.pub &gt;&gt; ./ssh/authorized_keys</p>
<p>The next step involves employing a bit of extra security. First, we change the access rights for the .ssh directory so that only the owner has read, write, and execute privileges. Next, we&#8217;ll make sure that the authorized_keys file can only be accessed by the owner. And finally, we&#8217;ll remove the previously uploaded offsite.pub key file, since it&#8217;s no longer required. It&#8217;s important to ensure that access permissions are properly set because the OpenSSH server may refuse to use keys which have non-secure access rights.</p>
<p>Listing 6. Changing permissions with chmod</p>
<p>[server1]$ chmod 700 .ssh<br />
[server1]$ chmod 600 ./ssh/authorized_keys<br />
[server1]$ rm offsite.pub<br />
[server1]$ exit</p>
<p>After completing the same process on server2, we are ready to return to the offsite storage machine to test the new passphrase type access. &gt;From the offsite server you could type the following:</p>
<p>[offsite]$ ssh -v accountname@server1.com</p>
<p>Use the -v, or verbose flag option, to display debugging information while verifying that your account is now able to access the remote server using the new passphrase rather than the original password. The debug output displays important information which you might not otherwise see, in addition to offering a high level view of how the authentication process works. You won&#8217;t need to specify the -v flag on subsequent connections; but it is quite useful to do so while testing a connection.</p>
<p>Automating machine access using ssh-agent</p>
<p>The ssh-agent program acts like a gatekeeper, securely providing access to security keys as needed. Once ssh-agent is started, it sits in the background and makes itself available to other OpenSSH applications such as ssh and scp programs. This allows the ssh program to request an already decrypted key, rather than asking you for the private key&#8217;s secret passphrase each time it&#8217;s required.</p>
<p>Let&#8217;s take a closer look at ssh-agent. When ssh-agent runs it outputs shell commands:</p>
<p>Listing 7. ssh-agent in action</p>
<p>[offsite]$ ssh-agent<br />
SSH_AUTH_SOCK=/tmp/ssh-XX1O24LS/agent.14179; export SSH_AUTH_SOCK;<br />
SSH_AGENT_PID=14180; export SSH_AGENT_PID;<br />
echo Agent pid 14180;</p>
<p>We can instruct the shell to execute the output commands which ssh-agent displays using the shell&#8217;s eval command:</p>
<p>[offsite]$ eval `ssh-agent`<br />
Agent pid 14198</p>
<p>The eval command tells the shell to evaluate (execute) the commands generated by the ssh-agent program. Make sure that you specify the back-quote character (`) and not a single quote! Once executed, the eval `ssh-agent` statement will return the agent&#8217;s process identifier. Behind the scenes, the SSH_AUTH_SOCK and SSH_AGENT_PID shell variables have been exported and are now available. You can view their values by displaying them to the shell console:</p>
<p>[offsite]$ echo $SSH_AUTH_SOCK<br />
/tmp/ssh-XX7bhIwq/agent.14197</p>
<p>The $SSH_AUTH_SOCK (short for SSH Authentication Socket) is the location of a local socket which applications can use to speak to ssh-agent. To ensure that the SSH_AUTH_SOCK and SSH_AGENT_PID variables are always registered, enter the eval `ssh-agent` statement into your ~/.bash_profile.</p>
<p>ssh-agent has now become a background process which is visible using the top and ps commands.</p>
<p>Now we&#8217;re ready to share our passphrase with ssh-agent. To do so, we must use a program called ssh-add, which adds (sends) our passphrase to the running ssh-agent program.</p>
<p>Listing 8. ssh-add for hassle-free login</p>
<p>[offsite]$ ssh-add<br />
Enter passphrase for /home/accountname/.ssh/id_dsa: (enter passphrase)<br />
Identity added: /home/accountname/.ssh/id_dsa<br />
(/home/accountname/.ssh/id_dsa)</p>
<p>Now when we access server1, we&#8217;re not prompted for a passphrase:</p>
<p>[offsite]$ ssh accountname@server1.com<br />
[server1]$ exit</p>
<p>If you&#8217;re not convinced, try removing (kill -9) the ssh-agent process and reconnecting to server1. This time, you&#8217;ll notice that server1 will request the passphrase for the private key stored in the id_dsa file in the .ssh directory:</p>
<p>[offsite]$ kill -9 $SSH_AGENT_PID<br />
[offsite]$ ssh accountname@server1.com<br />
Enter passphrase for key &#8216;/home/accountname/.ssh/id_dsa&#8217;:</p>
<p>Simplifying key access using keychain</p>
<p>So far, we&#8217;ve learned about several OpenSSH programs (ssh, scp, ssh-agent and ssh-add), and we&#8217;ve created and installed private and public keys to enable a secure and automated login process. You may have realized that most of our setup work only has to be done once. For example, the process of creating the keys, installing them, and getting ssh-agent to execute via a .bash_profile only has to be done once per machine. That&#8217;s the really good news.</p>
<p>The less than ideal news is that ssh-add must be invoked each time we sign on to the offsite machine and ssh-agent isn&#8217;t immediately compatible with the cron scheduling process which we&#8217;ll need to automate our backups. The reason that cron processes can&#8217;t communicate with ssh-agent is that cron jobs are executed as child processes by cron and thus do not inherit the $SSH_AUTH_SOCK shell variable.</p>
<p>Fortunately, there is a solution which not only eliminates limitations associated with ssh-agent and ssh-add, but also allows us to use cron to automate all sorts of processes requiring secure passwordless access to other machines. In his 2001 three-part developerWorks series, OpenSSH key management (see Resources for a link), Daniel Robbins presented a shell script called keychain, which is a front-end to ssh-add and ssh-agent and which simplifies the entire passwordless process. Over time, the keychain script has undergone a number of improvements and is now maintained by Aron Griffis, with a recent 2.3.2-1 release posted on June 17, 2004.</p>
<p>The keychain shell script is a bit too large to list in this article because the well-written script includes lots of error checking, ample documentation, and a generous serving of cross-platform code. However, keychain can be quickly downloaded from the project&#8217;s Web site (see Resources for a link).</p>
<p>Once you download and install keychain, using it is remarkably easy. Simply log in to each machine and add the following two lines to each .bash_profile:</p>
<p>keychain id_dsa<br />
. ~/.keychain/$HOSTNAME-sh</p>
<p>The first time you log back in to each machine, keychain will prompt you for the passphrase. However, keychain won&#8217;t ask you to reenter the passphrase on subsequent login attempts unless the machine has been restarted. Best of all, cron tasks are now able to use OpenSSH commands to securely access remote machines without requiring the interactive use of passphrases. Now we have the best of both worlds, added security and ease of use.</p>
<p>Listing 9. Initializing keychain on each machine</p>
<p>KeyChain 2.3.2; http://www.gentoo.org/projects/keychain<br />
Copyright 2002-2004 Gentoo Technologies, Inc.; Distributed under the<br />
GPL</p>
<p>* Initializing /home/accountname/.keychain/localhost.localdomain-sh<br />
file&#8230;<br />
* Initializing /home/accountname/.keychain/localhost.localdomain-csh<br />
file&#8230;<br />
* Starting ssh-agent<br />
* Adding 1 key(s)&#8230;<br />
Enter passphrase for /home/accountname/.ssh/id_dsa: (enter passphrase)</p>
<p>Scripting a backup process</p>
<p>Our next task is to create the shell scripts, which will perform the necessary backup operations. The goal is to perform a complete database backup of servers 1 and 2. In our example, each server is running the MySQL database server and we&#8217;ll use the mysqldump command-line utility to export a few database tables to an SQL import file.</p>
<p>Listing 10. The dbbackup.sh shell script for server 1</p>
<p>#!/bin/sh</p>
<p># change into the backup_agent directory where data files are stored.<br />
cd /home/backup_agent</p>
<p># use mysqldump utility to export the sites database tables<br />
mysqldump -u sitedb -pG0oDP@sswrd &#8211;add-drop-table sitedb &#8211;tables<br />
tbl_ccode tbl_machine tbl_session tbl_stats &gt; userdb.sql</p>
<p># compress and archive<br />
tar czf userdb.tgz userdb.sql</p>
<p>On server 2, we&#8217;ll place a similar script which backs up the unique tables present in the site&#8217;s database. Each script is flagged as executable using:</p>
<p>[server1]:$ chmod +x dbbackup.sh</p>
<p>With a dbbackup.sh file on servers 1 and 2, we return to the offsite data server, where we&#8217;ll create a shell script to invoke each remote dbbackup.sh script prior to initiating a transfer of the compressed (.tgz) data files.</p>
<p>Listing 11. backup_remote_servers.sh shell script for use on the offsite data server</p>
<p>#!/bin/sh</p>
<p># use ssh to remotely execute the dbbackup.sh script on server 1<br />
/usr/bin/ssh backup_agent@server1.com &#8220;/home/backup_agent/dbbackup.sh&#8221;</p>
<p># use scp to securely copy the newly archived userdb.tgz file<br />
# from server 1.  Note the use of the date command to timestamp<br />
# the file on the offsite data server.<br />
/usr/bin/scp backup_agent@server1.com:/home/backup_agent/userdb.tgz<br />
/home/backups/userdb-$(date +%Y%m%d-%H%M%S).tgz</p>
<p># execute dbbackup.sh on server 2<br />
/usr/bin/ssh backup_agent@server2.com &#8220;/home/backup_agent/dbbackup.sh&#8221;</p>
<p># use scp to transfer transdb.tgz to offsite server.<br />
/usr/bin/scp backup_agent@server2.com:/home/backup_agent/transdb.tgz<br />
/home/backups/transdb-$(date +%Y%m%d-%H%M%S).tgz</p>
<p>The backup_remote_servers.sh shell script uses the ssh command to execute a script on the remote servers. Because we&#8217;ve set up passwordless access, the ssh command is able to execute commands on servers 1 and 2 remotely from the offsite server. The entire authentication process is now handled automatically, thanks to keychain.</p>
<p>Scheduling</p>
<p>Our next and final task involves scheduling the execution of the backup_remote_servers.sh shell script on the offsite data storage server. We&#8217;ll add two entries to the cron scheduling server to request execution of the backup script twice per day, at 3:34 am and again at 8:34 pm. On the offsite server invoke the crontab program with the edit (-e) option.</p>
<p>[offsite]:$ crontab -e</p>
<p>The crontab invokes the default editor, as specified using the VISUAL or EDITOR shell environment variables. Next, type two entries and save and close the file.</p>
<p>Listing 12. Crontab entries on the offsite server</p>
<p>34 3 * * * /home/backups/remote_db_backup.sh<br />
34 20 * * * /home/backups/remote_db_backup.sh</p>
<p>A crontab line contains two main sections, a time schedule section followed by a command section. The time schedule is divided into fields for specifying when a command should be executed:</p>
<p>Listing 13. Crontab format</p>
<p>+&#8212;- minute<br />
| +&#8212;&#8211; hour<br />
| | +&#8212;&#8212; day of the month<br />
| | | +&#8212;&#8212; month<br />
| | | | +&#8212;- day of the week<br />
| | | | | +&#8211; command to execute<br />
| | | | | |<br />
34 3 * * * /home/backups/remote_db_backup.sh</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ezlinuxadmin.com/2008/07/linux-back-ups/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
