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_versiont1.2nn";
$config_content .= "# Path to binariesn";
$config_content .= "cmd_rsynct/usr/bin/rsyncn";
$config_content .= "cmd_ssht/usr/bin/sshn";
$config_content .= "cmd_cpt/bin/cpn";
$config_content .= "cmd_rmt/bin/rmn";
$config_content .= "cmd_dut/usr/bin/dun";
$config_content .= "cmd_loggert/usr/bin/loggernn";
$config_content .= "no_create_roott1nn";
$config_content .= "# Rsync argsn";
$config_content .= "rsync_short_argst-aznn";
$config_content .= "# Interval of how many backups to keepn";
$config_content .= "intervaltdailyt" . $config_row['daily'] . "n";
$config_content .= "intervaltweeklyt" . $config_row['weekly'] . "n";
$config_content .= "intervaltmonthlyt" . $config_row['monthly'] . "nn";
$config_content .= "# Level og verbosity (1 = lowest, 5 = highest)n";
$config_content .= "loglevelt5nn";
$config_content .= "# Rsync argsn";
$config_content .= "rsync_long_argst--stats --delete --numeric-ids --delete-excluded --port " . $config_row['port'] . "nn";
$config_content .= "# Root folder, logfile, lockfilen";
$config_content .= "snapshot_roott" . $config_row['filepath'] . "n";
$config_content .= "logfilet" . $config_row['filepath'] . "/rsnapshot.logn";
$config_content .= "lockfilet" . $config_row['filepath'] . "/rsnapshot.pidnn";
$config_content .= "# Folders that gets excludedn";
$config_content .= "excludet.recycle/nn";
$config_content .= "# Backup commands pr foldern";
$config_folders = explode(',',$config_row['folders']);
foreach ($config_folders as $value) {
    $config_content .= "backuptrsync://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_filen";
} 
else {
    echo "There was a problem while uploading $source_filen";
}
# close the connection
ftp_close($conn_id);
?>

是因为\t吗?如果是这样的话,可以做些什么呢?
任何帮助,不胜感激。

要解决选项卡不正确的问题,请在生成的文件上使用以下逗号:

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

Linux 中的 SED 实用程序将解析和转换文本。

相关内容

  • 没有找到相关文章

最新更新