Linux – Script launching 3 copies of rsync

bashlinuxrsync

I have a simple script that uses rsync to copy a Postgres database to a backup location for use with Point In Time Recovery. The script is run every 2 hours via a cron job for the postgres user. For some strange reason, I can see three copies of rsync running in the process list. Any ideas why this might the case?

Here's the cron entry:

# crontab -u postgres -l
PATH=/bin:/usr/bin:/usr/local/bin
0 */2 * * * /var/lib/pgsql/9.0/pitr_backup.sh

And here's the ps list, which shows two copies of rsync running and one sleeping:

# ps ax |grep rsync
 9102 ?        R      2:06 rsync -avW /var/lib/pgsql/9.0/data/ /var/lib/pgsql/9.0/backups/pitr_archives/20110629100001/ --exclude pg_xlog --exclude recovery.conf --exclude recovery.done --exclude pg_log
 9103 ?        S      0:00 rsync -avW /var/lib/pgsql/9.0/data/ /var/lib/pgsql/9.0/backups/pitr_archives/20110629100001/ --exclude pg_xlog --exclude recovery.conf --exclude recovery.done --exclude pg_log
 9104 ?        R      2:51 rsync -avW /var/lib/pgsql/9.0/data/ /var/lib/pgsql/9.0/backups/pitr_archives/20110629100001/ --exclude pg_xlog --exclude recovery.conf --exclude recovery.done --exclude pg_log

And here's the uber simple script that seems to be the cause of the problem:

#!/bin/sh

LOG="/var/log/pgsql-pitr-backup.log"
base_backup_dir="/var/lib/pgsql/9.0/backups"

wal_archive_dir="$base_backup_dir/wal_archives"
pitr_archive_dir="$base_backup_dir/pitr_archives"

timestamp=`date +%Y%m%d%H%M%S`
backup_dir="$pitr_archive_dir/$timestamp"

mkdir -p $backup_dir

echo `date` >> $LOG

/usr/bin/psql -U postgres -c "SELECT pg_start_backup('$backup_dir');"

rsync -avW /var/lib/pgsql/9.0/data/ $backup_dir/ --exclude pg_xlog --exclude recovery.conf --exclude recovery.done --exclude pg_log

/usr/bin/psql -U postgres -c "SELECT pg_stop_backup();"

Best Answer

It's normal for rsync to fork multiple processes, it looks like that's what's going on here, it's nothing to be concerned with. The fact that the process IDs are sequential in the ps output would very strongly indicate that they're not jobs that are still running two hours later when the next job starts.

Related Topic