本地rsync包含/排除

时间:2011-07-24 22:10:37

标签: rsync

我似乎无法获得备份/ etc / php5,/ etc / apache2和/ etc / mysql的命令。我正在使用两个因为我无法弄清楚如何在一个中做到这两个。第一个有效:

rsync -vahtl --dry-run --log-file=$LOGFILE --exclude="wp-includes/" --exclude="wp-admin/" --exclude="wp-*.php" /var/www $DROPBOX_FOLDER

但是当我运行第二个时,我尝试了一堆--include和--exclude指令变体,但没有任何作用:

rsync -vahtl --dry-run --log-file=$LOGFILE --include="php5" --exclude="*" /etc $DROPBOX_FOLDER
rsync -vahtl --dry-run --log-file=$LOGFILE --include="*/" --include="php5/" --exclude="*" /etc $DROPBOX_FOLDER

等。

1 个答案:

答案 0 :(得分:0)

最快的方法是使用类似这样的东西将其作为bash脚本运行。需要根据你的Linux风格进行调整

#!/bin/sh
# rsync backup script
rsync -avz --delete-excluded --exclude-from=backup.lst / /home/USERNAME/Dropbox/backup

然后在您将从中运行脚本的目录中创建一个名为backup.lst的文件     #include     + / etc / php5     + / etc / apache2     + / etc / mysql     + / var / www

# Exclude
- /var/www/wp-admin/*
- /var/www/wp-*.php
- /var/www/wp-includes/*
- /etc/*
- /run/*
- /proc/*
- /sys/*
- /tmp/*
- lost+found/
- /media/*
- /mnt/*

以下是一些排除/包含示例:

# --exclude "*.o"   would exclude all filenames matching *.o
# --exclude "/foo"  would exclude a file in the base directory called foo
# --exclude "foo/"  would exclude any directory called foo.
# --exclude "/foo/*/bar"  would exclude any file called bar two levels below a
                      base directory called foo.
# --exclude "/foo/**/bar" would exclude any file called bar two or more levels below
                      a base directory called foo.
# --include "*/" --include "*.c" --exclude "*"
                      would include all directories
                      and C source files
# --include "foo/" --include "foo/bar.c" --exclude "*"
                would include only foo/bar.c (the foo/ directory must be
                explicitly included or it would be excluded by the "*")