- Backing Up FreeBSD With SMBFS
- Performing backups is one of the most important tasks a good administrator can perform. This applies not only to FreeBSD administrators but administrators of other operating systems as well. When things go wrong, as they sometimes do, a good backup can save the day or a lack thereof, can ruin it.
- Backups can be performed with hardware as basic as a SCSI tape drive that uses 8mm tape cartriges to more advanced systems like AIT tape library systems using cartriges that can store up to 50GB of compressed data.
- But what can an administrator do without the luxury of such hardware? Since most networks are comprised of more than one system or server that is being backed up, it is possible to send the archived data of one server across the network to a share of another server that is being backed up.
- This article describes the procedure used to backup data on a FreeBSD system using the "tar/gzip" archiving utilities and the "smbutil/mount_smbfs" commands to transport that data to network shares. These procedures were tested on FreeBSD 4.6-STABLE.
- Adding NETSMB Kernel Support
- The first task that should be performed is to add the proper "options" lines to the custom kernel configuration file for SMB support. For information on building a custom kernel, refer to section 9.3 Building and Installing a Custom Kernel of the FreeBSD Handbook and relevant information contained in /usr/src/sys/i386/conf/LINT.
- The following options should be added under the "makeoptions" section of the kernel configuration file:
- options NETSMB #SMB/CIFS requester options NETSMBCRYPTO #encrypted password support for SMB options LIBMCHAIN #mbuf management library options LIBICONV options SMBFS
- Establishing a SMB Connection with a Host System
- After SMB support has been compiled into the kernel configuration file, the next step is to decide which system on the network to connect to. Obviously, it will need to be a system that has an active share on the network and has enough disk space available to hold your archives. The host system will also need to be one that's being backed up regularly. Once you have chosen the proper host system, establish a SMB connection via the "smbutil" command:
- #smbutil login //jwarner@smbserver1 Password: Connected to smbserver1
- To logout:
- #smbutil logout //jwarner@smbserver1 Password: Connection unmarked as permanent and will be closed when possible
- See "man smbutil" for a more information.
- Mounting a Share with the "mount_smbfs" Command
- After establishing a connection with the host system, create a mount point:
- You can name this directory anything you want. For the purposes of this example, I'll create a mount point directory called "backup".
- #mkdir /backup
- Next, reestablish a connection with the host system and mount it's share:
- #smbutil login //jwarner@smbserver1 Password: Connected to smbserver1
- #mount_smbfs -N //jwarner@smbserver1/sharename /backup #
- The "-N" switch specifies not to ask for a password. See "man mount_smbfs" for more information.
- Archiving and Compressing Data with tar and gzip
- After a successful connection with the host server has been established and it's network share has been mounted, the desired data can be archived and copied to the network share. There are different ways this can be accomplished but for this example, I will create a simple shell script inside the mounted share that will generate compressed archives of desired files and/or directories.
- I will make compressed archives of the /boot, /etc, /home and /usr/local/etc directories with the "tar" and "gzip" utilities. These are just examples but as a minimum, I recommend including the /etc and /usr/local/etc directories as they contain important configuration files. See "man hier" for a complete description of the FreeBSD directory structure. Also refer to "man tar" and "man gzip" for a complete description of these utilities.
- #cd /backup #vi bkup
- I named this file "bkup" but you can name it whatever you wish.
- Note: This script is an example. There are many ways that the tar archiving utility can be used. Read Tar(1) carefully and tailor to suit your needs.
- #!/bin/sh
- tar cvvpzf boot.tar.gz /boot tar cvvpzf etc.tar.gz /etc tar cvvpzf home.tar.gz /home tar cvvpzf usr_local_etc.tar.gz /usr/local/etc
- Be sure to make this file executable:
- #chmod 755 bkup
- Now, run the script to create the archives:
- #./bkup tar: Removing leading / from absolute path names in the archive. drwxr-xr-x root/wheel 0 Jun 23 18:19 2002 boot/ drwxr-xr-x root/wheel 0 May 11 19:46 2002 boot/defaults/ -r--r--r-- root/wheel 10957 May 11 19:46 2002 boot/defaults/loader.conf -r--r--r-- root/wheel 512 Jun 23 18:19 2002 boot/mbr -r--r--r-- root/wheel 512 Jun 23 18:19 2002 boot/boot0 -r--r--r-- root/wheel 512 Jun 23 18:19 2002 boot/boot1 -r--r--r-- root/wheel 7680 Jun 23 18:19 2002 boot/boot2 -r-xr-xr-x root/wheel 1136 Jun 23 18:19 2002 boot/cdboot -r--r--r-- root/wheel 12012 Jan 28 06:12 2002 boot/loader.help -r--r--r-- root/wheel 338 Jan 28 06:12 2002 boot/loader.rc -r--r--r-- root/wheel 9237 Jan 28 06:12 2002 boot/loader.4th -r--r--r-- root/wheel 25121 Jan 28 06:12 2002 boot/support.4th -r-xr-xr-x root/wheel 155648 Jun 23 18:19 2002 boot/loader -r-xr-xr-x root/wheel 157696 Jun 23 18:19 2002 boot/pxeboot
- After the script finishes running, you will notice *.tar.gz files of the directories you chose to archive:
- #ls | more bkup boot.tar.gz etc.tar.gz home.tar.gz usr_local_etc.tar.gz
- Conclusion
- After successfully creating archives on a host share, there are a couple of options. You can perform these procedures manually once or twice a week but a better approach might be to write a shell script that performs all of the above and add it to the "cron" schedular to run on scheduled days and times. You could even add individual command entries to cron in order to accomplish this.
- Whether or not you choose the methods described in this article isn't important but getting good backups, regardless of how you do it, is. Facing the problem of deleted or corrupted data isn't a matter of "if" but rather a matter of "when" and this is why good backups are essential.
- Original URL: http://ezine.daemonnews.org/200208/smbfs.html
- Content Copyright © Original Author
