Пример #1
0
function exec_webdav()
{
    $mount = new mount();
    $unix = new unix();
    $mount_point = $GLOBALS["MOUNT_POINT"];
    @mkdir($mount_point, 0755, true);
    $server = $GLOBALS["CyrusBackupNas"]["WEBDAV_SERVER"];
    $username = $GLOBALS["CyrusBackupNas"]["WEBDAV_USER"];
    $password = $GLOBALS["CyrusBackupNas"]["WEBDAV_PASSWORD"];
    $path = $GLOBALS["CyrusBackupNas"]["WEBDAV_DIR"];
    if ($mount->ismounted($mount_point)) {
        $mount->umount($mount_point);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs:WEBDAV_DIR...: {$path}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs:WEBDAV_SERVER: {$server}\n";
    }
    if (!$mount->davfs_mount($mount_point, $server, $username, $password, $path)) {
        if ($GLOBALS["VERBOSE"]) {
            echo $mount->events_compile() . "\n";
        }
        cyrus_admin_mysql(0, "Unable to connect to {$server}", $mount->events_compile(), __FILE__, __LINE__);
        return;
    }
    $path = $mount->davfs_path($mount_point, $server, $username, $password, $path);
    if ($GLOBALS["VERBOSE"]) {
        echo "davfs_path: {$path}\n";
    }
    $hostname = $unix->hostname_g();
    $GLOBALS["DIRBYTES"] = date("YmdH");
    $GLOBALS["MOUNTED_PATH__BACKUPDIR"] = "{$GLOBALS["MOUNT_POINT"]}/{$path}/{$hostname}";
    $GLOBALS["MOUNTED_PATH_FINAL"] = "{$GLOBALS["MOUNT_POINT"]}/{$path}/{$hostname}/{$GLOBALS["DIRBYTES"]}";
    $GLOBALS["MOUNTED_PATH_FINAL"] = str_replace("//", "/", $GLOBALS["MOUNTED_PATH_FINAL"]);
    if ($GLOBALS["VERBOSE"]) {
        echo "MOUNTED_PATH_FINAL: {$GLOBALS["MOUNTED_PATH_FINAL"]}\n";
    }
    if (!is_dir($GLOBALS["MOUNTED_PATH_FINAL"])) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Create -> {$GLOBALS["MOUNTED_PATH_FINAL"]}\n";
        }
        @mkdir($GLOBALS["MOUNTED_PATH_FINAL"], 0755, true);
        if (!is_dir($GLOBALS["MOUNTED_PATH_FINAL"])) {
            cyrus_admin_mysql(0, "Unable to backup: Permission denied on WebDAV resource {$server}", "For creating directory {$GLOBALS["MOUNTED_PATH_FINAL"]}", __FILE__, __LINE__);
            killNas();
            return;
        }
    }
    $t = time();
    @touch("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}");
    if (!is_file("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}")) {
        cyrus_admin_mysql(0, "Unable to backup: Permission denied on WebDAV", "resource {{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}}", __FILE__, __LINE__);
        killNas();
        return;
    }
    @unlink("{$GLOBALS["MOUNTED_PATH_FINAL"]}/{$t}");
    if ($GLOBALS["VERBOSE"]) {
        echo "backup_ldap():\n";
    }
    backup_ldap();
    if ($GLOBALS["VERBOSE"]) {
        echo "backup_cyrus():\n";
    }
    backup_cyrus();
    remove_containers();
    killNas();
}