Create an rsyncd.service fedora 16


Linux 備份策略


Create an rsyncd.service fedora 16

David Highley dhighley at
Tue Nov 29 00:57:02 UTC 2011

"David Highley wrote:"
>> "T.C. Hollingsworth wrote:"

Thanks to T.C. Hollingsworth for helping us implement this service.
Steps to creating an rsyncd service that works with systemd on fedora

Create configuration for rsyncd server.
- mkdir /etc/rsyncd
- touch /etc/rsyncd.motd
- touch /etc/rsyncd.secrets
- edit /etc/rsyncd.conf
pid file=/var/run/
address=<server address>
use chroot=yes
read only=no

# limit access to from allowed hosts only
hosts allow=<space separated host addresses>
hosts deny=*

motd file=/etc/rsyncd/rsyncd.motd

log format=%t%a%m%f%b
log file=/var/log/rsyncd.log

[module name]
#secrets file=/etc/rsysncd/rsyncd.secrets
comment=<module comment string>

In the directory /lib/systemd/system create two files.
- rsyncd at .service
Description=rsyncd Rsync Daemon

ExecStart=/usr/bin/rsync --config=/etc/rsyncd/rsyncd.conf --daemon

- rsyncd.socket
Description=rsyncd Service Sockets



Reload systemd daemon, enable and start the service.
- systemctl --system daemon-reload
- systemctl enable rsyncd.socket
- systemctl start rsyncd.socket
Be Sociable, Share!

1 則迴響於《Create an rsyncd.service fedora 16

  1. rsync examples
    If you have an interesting example of how you use rsync then please submit it to the for inclusion on this page.
    backup to a central backup server with 7 day incremental


    # This script does personal backups to a rsync backup server. You will end up
    # with a 7 day rotating incremental backup. The incrementals will go
    # into subdirectories named after the day of the week, and the current
    # full backup goes into a directory called “current"

    # directory to backup

    # excludes file – this contains a wildcard pattern per line of files to exclude

    # the name of the backup machine

    # your password on the backup server


    BACKUPDIR=`date +%A`
    OPTS="–force –ignore-errors –delete-excluded –exclude-from=$EXCLUDES
    –delete –backup –backup-dir=/$BACKUPDIR -a"

    export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

    # the following line clears the last weeks incremental directory
    [ -d $HOME/emptydir ] || mkdir $HOME/emptydir
    rsync –delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
    rmdir $HOME/emptydir

    # now the actual transfer
    rsync $OPTS $BDIR $BSERVER::$USER/current

    backup to a spare disk

    I do local backups on several of my machines using rsync. I have an
    extra disk installed that can hold all the contents of the main
    disk. I then have a nightly cron job that backs up the main disk to
    the backup. This is the script I use on one of those machines.


    export PATH=/usr/local/bin:/usr/bin:/bin

    LIST="rootfs usr data data2″

    for d in $LIST; do
    mount /backup/$d
    rsync -ax –exclude fstab –delete /$d/ /backup/$d/
    umount /backup/$d

    DAY=`date “+%A"`

    rsync -a –delete /usr/local/apache /data2/backups/$DAY
    rsync -a –delete /data/solid /data2/backups/$DAY

    The first part does the backup on the spare disk. The second part
    backs up the critical parts to daily directories. I also backup the
    critical parts using a rsync over ssh to a remote machine.

    mirroring vger CVS tree

    The cvs tree is mirrored onto via
    anonymous rsync using the following script.


    cd /var/www/cvs/vger/

    RUN=`lps x | grep rsync | grep -v grep | wc -l`
    if [ "$RUN" -gt 0 ]; then
    echo already running
    exit 1

    rsync -az $HOME/ChangeLog

    sum1=`sum $HOME/ChangeLog`
    sum2=`sum /var/www/cvs/vger/CVSROOT/ChangeLog`

    if [ "$sum1" = "$sum2" ]; then
    echo nothing to do
    exit 0

    rsync -az –delete –force /var/www/cvs/vger/
    exit 0

    Note in particular the initial rsync of the ChangeLog to determine if
    anything has changed. This could be omitted but it would mean that the
    rsyncd on vger would have to build a complete listing of the cvs area
    at each run. As most of the time nothing will have changed I wanted to
    save the time on vger by only doing a full rsync if the ChangeLog has
    changed. This helped quite a lot because vger is low on memory and
    generally quite heavily loaded, so doing a listing on such a large
    tree every hour would have been excessive.

    automated backup at home

    I use rsync to backup my wifes home directory across a modem link each
    night. The cron job looks like this

    cd ~susan
    dest=~/backup/`date +%A`
    mkdir $
    find . -xdev -type f \( -mtime 0 -or -mtime 1 \) -exec cp -aPv “{}"
    $ \;
    cnt=`find $ -type f | wc -l`
    if [ $cnt -gt 0 ]; then
    rm -rf $dest
    mv $ $dest
    rm -rf $
    rsync -Cavze ssh . samba:backup
    } >> ~/backup/backup.log 2>&1

    note that most of this script isn’t anything to do with rsync, it just
    creates a daily backup of Susans work in a ~susan/backup/ directory so
    she can retrieve any version from the last week. The last line does
    the rsync of her directory across the modem link to the host
    samba. Note that I am using the -C option which allows me to add
    entries to .cvsignore for stuff that doesn’t need to be backed up.

    Fancy footwork with remote file lists

    One little known feature of rsync is the fact that when run over a
    remote shell (such as rsh or ssh) you can give any shell command as
    the remote file list. The shell command is expanded by your remote
    shell before rsync is called. For example, see if you can work out
    what this does:

    rsync -avR remote:’`find /home -name “*.[ch]“`’ /tmp/

    note that that is backquotes enclosed by quotes (some browsers don’t
    show that correctly).