25
Wed, Dec
0 New Articles

The Linux Letter: Getting in Rsync

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

I've always been a believer in the philosophy of centralized file storage. For the user, a centralized file server provides a single place to find his files, which is particularly important if he tends to move from desk to desk via the Window's "Roaming Profiles" feature. For the administrator (read: you and I), a centralized server simplifies backup and maintenance. Once configured, the centralized server scenario provides a semblance of serenity for everyone. (Try to say that last sentence three times fast!) Unfortunately, laptop computers were dropped squarely in the middle of our tranquil pond of computing, causing a big splash and massive waves that continue to lap at its shores. Once laptops (and more recently PDAs and PMTs) came onto the scene, a method of synchronizing offline files with those on the file server became necessary, since the whole point of mobile computing is to allow mobility from the office and its server. What to do?

One solution available to Windows users is My Briefcase. This brute-force approach compares the timestamps of files contained within the Briefcase folder with their counterparts on the file server, ensuring that the newest version ends up in the appropriate place. I describe this feature as being "brute force" because, when compared with the topic of this month's article, it is. A more elegant solution is the rsync tool.

My Briefcase on Steroids

What makes rsync elegant? For starters, rsync uses an algorithm created by Andrew Tridgell (of Samba fame) that creates a diff (difference) between the two files being compared and transmits that diff instead of the entire file. While not terribly important for smaller files, this feature can yield a huge performance improvement while syncing large files over a dial-up or otherwise bandwidth-constrained connection. On top of this, rsync can compress the diff file for transmission, further enhancing the effect.

Rsync can do more than just synchronize files. It can synchronize entire directories. This feature can be used to produce mirrors between systems--such as a primary Web server and its backups. Similarly, I maintain a simple Web site on my laptop computer. When I'm ready to publish it, I run a script that invokes rsync. This is shown in Figure 1.

#!/bin/sh 

#HOST=www.bearcatwrestling.org
HOST=www.mydomain.com
BASEDIR=www/mywebsite.org

# The command line parameters are:
-a = use archive mode
 v = be verbose
    z = use compression on transfer
    e = specify rsh replacement (use ssh)
--delete = delete files on server missing on client
rsync -avze ssh --delete  --exclude 'CVS*' 
--exclude *~ 
--exclude 'publish.sh' 
--exclude '*.*sql' 
--exclude *xvpics* 
./ $HOST:$BASEDIR

 

Figure 1: This simple script permits me to easily publish a Web site.

For securely syncing across a public network, rsync can use secure shell (ssh) as its transport. This ensures that the credentials used during the rsync initialization process can't be snooped.

Since it can perform its magic over directories, rsync is quite adept at being a backup solution for laptop computers. I have a script scheduled on my laptop that performs a backup on a nightly basis, copying the changed files to my desktop. Rsync will accept command line parameters (or parameters from a text file) that indicate which files or directories are to be included or excluded, so I can easily omit browser caches. If I want my backup to look like the current state of my laptop, I can instruct rsync to delete files on the server that are missing on the laptop. Alternatively, I can let deleted files live on the server.

I have just scratched the surface of what rsync can do. For a better picture of rsync's capabilities, visit the project Web site and check out the features page and the examples page.

Although developed primarily for *nix-like operating systems, rsync can run on Windows via the Cygwin environment (discussed last month) as well as on the iSeries under PASE. Cygwin and most distributions of Linux already include rsync. If you want the latest version (or you want to run it under PASE), you can point your browser to the rsync home page.

Rsync and iSeries

Running rsync under Cygwin or Linux is straightforward, but it's beyond the scope of this article. Running rsync on the iSeries requires a minimal amount of additional effort. The reason? Normally, an invocation of rsync from a client to a server causes the server to invoke a copy of rsync with which the copy running on the client will communicate. Using rsync on the iSeries requires a different technique. To successfully synchronize between an iSeries and any other platform, you'll need to run rsync in daemon mode. The additional effort I mentioned comes from having to create two additional files that will define the behavior of the rsync daemon. But before I discuss them, let me show you how to get rsync installed on your iSeries.

Installation

Installation on the iSeries involves the following steps:

1. Obtain the rsync program.

2. Load it onto the iSeries IFS.

3. Add some configuration files.

4. Run it.

Let's examine each of the steps in more detail now.

Step one is very easy to complete. The iSeries PASE enables you to run AIX binaries and, conveniently, rsync is available precompiled for AIX 4.5 from the rsync download page. Download the binary (which, at the time of this writing, is rsync-2.4.5.AIX43.tar.gz) and use FTP to transfer the file to a directory in the IFS of your iSeries (making sure you use the FTP "bin" directive when uploading the file).

Step two requires a few more gyrations. The file that you downloaded is a tape archive (tar) file and is compressed using gzip (as indicated by the tar.gz extension). This provides the first obstacle because it needs to be "gunzipped" prior to installation. Curiously, gunzip is not provided on my V4R5 edition of PASE (newer versions may have it); but, surprisingly, it is available using QSHELL. So, the first thing you must do is start a QSHELL session via the OS/400 command QSH or STRQSH. Once you are presented with a prompt ("$"), change to the directory in which you FTPed the file; then issue this command:

gunzip rsync-2.4.5.AIX43.tar.gz 

This creates the file rsync-2.4.5.AIX43.tar. This file is the tar file from which you'll do the installation. All of this is shown in Figure 2.

http://www.mcpressonline.com/articles/images/2002/bmps00.png

Figure 2: These steps result in a tar file usable from PASE. (Click images to enlarge.)

Next, end the QSHELL session by pressing F3; then, start a PASE session from an OS/400 session by typing this command:

call qp2term

As a matter of course, I tend to place files that I am adding to an existing system in the /opt directory. This makes it easier to maintain or remove them later. I use the following command to make the directory into which I'm going to install rsync:

mkdir -p /opt/rsync

I then make that directory the current directory by issuing this command:

cd /opt/rsync 

Finally, I extract the binaries by issuing this command:

tar -xf /home/klinebl/rsync-2.4.5.AIX43.tar 

A quick ls command confirms the success of the operation.

Now, create a symbolic link from the rsync binary into the /usr/bin directory so that it can be run without providing the complete path name. This is accomplished via cd /usr/bin followed by the command ln -sf /opt/rsync/bin/rsync. All of this is shown in Figure 3. Please note that the tar file also includes the manual pages. You can delete those with the command rm -rf /opt/rsync/man, since PASE doesn't include the *nix manual reader.

http://www.mcpressonline.com/articles/images/2002/bmps01.png

Figure 3: This screen shows the command that will provide you with a working rsync client on the iSeries.

At this point, you have an active rsync installation that requires only the addition of two configuration files. The first, /etc/rsyncd.conf, contains the configuration information that rsync uses when in daemon mode. The second, /etc/rsyncd.scrt, contains authentication information. These are shown in Figure 4, along with comments about the entries.

------ /etc/rsyncd.conf ---------
# This is the file that rsync will log to.  Useful
# for debugging your configuration!
log file = /usr/local/rsync/rsync.log

# The next line defines what could be called a "share."
[kline]
path = /home/klinebl
comment = My server
# The uid and gid are UserID and GroupID.  The iSeries
# has both. This will be the owner of the files rsynced
# for this share
uid = klinebl
gid = klinebl
# Allow bi-directional synchronization.
read only = no
list = yes
# The authorized users for this share.  They need
# to be listed in the /etc/rsyncd.scrt file
auth users = klinebl
# File for authentication of this share
secrets file = /etc/rsyncd.scrt

------ /etc/rsyncd.scrt ---------
# Note that the users listed here aren't necessarily
# "real" users on your iSeries.
klinebl:mypass

 

Figure 4: The contents of the configuration files for rsync are shown here. This is an extremely simple example.

I created these files on my Linux machine and used FTP to transfer them to the /etc directory on my iSeries. You could do the same thing via the Windows Notepad utility. The full documentation on the configuration files is available on your Linux box (if you have one) via man rsyncd.conf. Alternately, the docs are available on the Web Site.

Step four is simply to run the command to start rsync. From the qp2term command session, issue this command:

rsync --daemon 

If things are working properly, you should be returned to a command line. To verify that the program is really running, switch to an OS/400 command line and type netstat. From the menu presented, select option 3 (Work with TCP/IP connection status); then, scroll down until you find a listener on port 873. That's rsync awaiting your command.

Final Check and Check Out

When everything is up and running, you can check out your installation by running the following command from the qp2term session:

 rsync localhost:: 

If you are successful, you should see a screen that looks something like Figure 5. Obviously, the values that you provide in your rsyncd.conf file will determine the results you see from this test.

http://www.mcpressonline.com/articles/images/2002/bmps02.png

Figure 5: This is the result of a successful installation.

In this article, I given you instructions on how to perform a basic setup on your iSeries, since this is non-intuitive and not specifically mentioned in the documentation. There are far too many different combinations of client/servers and too many scenarios for which rsync can be utilized for me to describe them all. Your best bet is to visit the rsync Web site and nose around. Once you get started, you'll find rsync to be an invaluable tool.

Barry L. Kline is a consultant and has been developing software on various DEC and IBM midrange platforms for over 20 years. Barry discovered Linux back in the days when it was necessary to download diskette images and source code from the Internet. Since then, he has installed Linux on hundreds of machines, where it functions as servers and workstations in iSeries and Windows networks. He recently co-authored the book Understanding Linux Web Hosting with Don Denoncourt. Barry can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: