php rsnapshot配置生成器,选项卡无法正常工作

时间:2015-01-20 14:10:23

标签: php rsnapshot

我正在尝试使用脚本创建rsnapshot配置文件,脚本创建文件并将其上传到备份服务器就好了。

注意:两台服务器都运行centos6

一旦我尝试在备份服务器上运行它,我就会遇到以下错误:

ERROR: /backup/config/rsnapshot_56.conf on line 2:
ERROR: config_version 1.2 - config_version not recognized!
ERROR: /backup/config/rsnapshot_56.conf on line 12:
ERROR: no_create_root 1 - no_create_root must be set to either 1 or 0
ERROR: /backup/config/rsnapshot_56.conf on line 15:
ERROR: rsync_short_args -az - rsync_short_args "-az " not in correct format
ERROR: /backup/config/rsnapshot_56.conf on line 17:
ERROR: interval daily 10 - "10 " is not a legal value for a retention count
ERROR: /backup/config/rsnapshot_56.conf on line 18:
ERROR: interval weekly 4 - "4 " is not a legal value for a retention count
ERROR: /backup/config/rsnapshot_56.conf on line 20:
ERROR: interval monthly 0 - "0 " is not a legal value for a retention count
ERROR: /backup/config/rsnapshot_56.conf on line 23:
ERROR: loglevel 5 - loglevel must be a value between 1 and 5
ERROR: ---------------------------------------------------------------------
ERROR: Errors were found in /backup/config/rsnapshot_56.conf,
ERROR: rsnapshot can not continue. If you think an entry looks right, make
ERROR: sure you don't have spaces where only tabs should be.

根据错误,会看到配置文件包含rsnapshot中不允许的空格,但文件没有?

$ argv [1]等于数据库中的id php看起来如下:     

$source_file = "temp.conf";
$remote_file = "rsnapshot_".$argv[1].".conf";
$ftp_server = "xxxx";
$ftp_user_name = "xxxx";
$ftp_user_pass = "xxxx";

$config_sql = "SELECT * FROM xxxx WHERE id = ". $argv[1];
$config_result = mysqli_query($con, $config_sql);
$config_row = mysqli_fetch_array($config_result);

# Create/Edit the temp file with the config that is going to be uploaded
$config_file = fopen($source_file, "w+b") or die("Unable to open file!");
$config_content = "";
$config_content .= "config_version\t1.2\n\n";
$config_content .= "# Path to binaries\n";
$config_content .= "cmd_rsync\t/usr/bin/rsync\n";
$config_content .= "cmd_ssh\t/usr/bin/ssh\n";
$config_content .= "cmd_cp\t/bin/cp\n";
$config_content .= "cmd_rm\t/bin/rm\n";
$config_content .= "cmd_du\t/usr/bin/du\n";
$config_content .= "cmd_logger\t/usr/bin/logger\n\n";
$config_content .= "no_create_root\t1\n\n";
$config_content .= "# Rsync args\n";
$config_content .= "rsync_short_args\t-az\n\n";
$config_content .= "# Interval of how many backups to keep\n";
$config_content .= "interval\tdaily\t" . $config_row['daily'] . "\n";
$config_content .= "interval\tweekly\t" . $config_row['weekly'] . "\n";
$config_content .= "interval\tmonthly\t" . $config_row['monthly'] . "\n\n";
$config_content .= "# Level og verbosity (1 = lowest, 5 = highest)\n";
$config_content .= "loglevel\t5\n\n";
$config_content .= "# Rsync args\n";
$config_content .= "rsync_long_args\t--stats --delete --numeric-ids --delete-excluded --port " . $config_row['port'] . "\n\n";
$config_content .= "# Root folder, logfile, lockfile\n";
$config_content .= "snapshot_root\t" . $config_row['filepath'] . "\n";
$config_content .= "logfile\t" . $config_row['filepath'] . "/rsnapshot.log\n";
$config_content .= "lockfile\t" . $config_row['filepath'] . "/rsnapshot.pid\n\n";
$config_content .= "# Folders that gets excluded\n";
$config_content .= "exclude\t.recycle/\n\n";
$config_content .= "# Backup commands pr folder\n";

$config_folders = explode(',',$config_row['folders']);
foreach ($config_folders as $value) {
    $config_content .= "backup\trsync://backup@" . $config_row['ip'] . "/".$value."\t".$value."/\n";
}

fwrite($config_file, $config_content);
fclose($config_file);

# Set up basic connection
$conn_id = ftp_connect($ftp_server);

# login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

# upload the config file
if (ftp_put($conn_id, $remote_file, $source_file, FTP_ASCII)) {
    echo "successfully uploaded $source_file\n";
} 
else {
    echo "There was a problem while uploading $source_file\n";
}

# close the connection
ftp_close($conn_id);
?>

是因为\ t?如果是这样的话,可以做些什么呢? 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

要修复错误标签的问题,请在生成的文件上使用以下命令:

sed -i -e 's/\r$//' /path/to/rsnapshot.conf

linux中的sed实用程序将解析和转换文本。