Example #1
0
/*
 * Get the checkpoint (snapshot) creation time.
 * This is necessary to check for checkpoints not being stale.
 */
int
tlm_get_chkpnt_time(char *path, int auto_checkpoint, time_t *tp, char *jname)
{
    char volname[TLM_VOLNAME_MAX_LENGTH];
    char chk_name[PATH_MAX];
    char *cp_nm;

    NDMP_LOG(LOG_DEBUG, "path [%s] auto_checkpoint: %d",
             path, auto_checkpoint);

    if (path == NULL || *path == '\0' || tp == NULL)
        return (-1);

    if (get_zfsvolname(volname, TLM_VOLNAME_MAX_LENGTH,
                       path) == -1)
        return (-1);

    if (auto_checkpoint) {
        NDMP_LOG(LOG_DEBUG, "volname [%s]", volname);
        (void) snprintf(chk_name, PATH_MAX, "%s", jname);
        return (chkpnt_creationtime_bypattern(volname, chk_name, tp));
    }
    cp_nm = strchr(volname, '@');
    NDMP_LOG(LOG_DEBUG, "volname [%s] cp_nm [%s]", volname, cp_nm);

    return (chkpnt_creationtime_bypattern(volname, cp_nm, tp));
}
Example #2
0
/*
 * Check if the volume type is snapshot volume
 */
boolean_t
fs_is_chkpntvol(char *path)
{
    zfs_handle_t *zhp;
    char vol[ZFS_MAXNAMELEN];

    if (!path || !*path)
        return (FALSE);

    if (get_zfsvolname(vol, sizeof (vol), path) == -1)
        return (FALSE);

    (void) mutex_lock(&zlib_mtx);
    if ((zhp = zfs_open(zlibh, vol, ZFS_TYPE_DATASET)) == NULL) {
        (void) mutex_unlock(&zlib_mtx);
        return (FALSE);
    }

    if (zfs_get_type(zhp) != ZFS_TYPE_SNAPSHOT) {
        zfs_close(zhp);
        (void) mutex_unlock(&zlib_mtx);
        return (FALSE);
    }
    zfs_close(zhp);
    (void) mutex_unlock(&zlib_mtx);

    return (TRUE);
}
Example #3
0
/*
 * ndmp_remove_snapshot
 *
 * This function will parse the path to get the real volume name.
 * It will then remove the snapshot for that volume and job name.
 * This function should be called after NDMP backup is finished.
 *
 * Parameters:
 *   vol_name (input) - name of the volume
 *
 * Returns:
 *   0: on success
 *   -1: otherwise
 */
int
ndmp_remove_snapshot(char *vol_name, char *jname)
{
	char vol[ZFS_MAXNAMELEN];

	if (vol_name == 0 ||
	    get_zfsvolname(vol, sizeof (vol), vol_name) == -1)
		return (0);

	return (snapshot_destroy(vol, jname, B_FALSE, B_TRUE, NULL));
}
Example #4
0
/*
 * ndmp_create_snapshot
 *
 * This function will parse the path to get the real volume name.
 * It will then create a snapshot based on volume and job name.
 * This function should be called before the NDMP backup is started.
 *
 * Parameters:
 *   vol_name (input) - name of the volume
 *
 * Returns:
 *   0: on success
 *   -1: otherwise
 */
int
ndmp_create_snapshot(char *vol_name, char *jname)
{
	char vol[ZFS_MAXNAMELEN];

	if (vol_name == 0 ||
	    get_zfsvolname(vol, sizeof (vol), vol_name) == -1)
		return (0);

	/*
	 * If there is an old snapshot left from the previous
	 * backup it could be stale one and it must be
	 * removed before using it.
	 */
	if (ndmp_has_backup_snapshot(vol, jname))
		(void) snapshot_destroy(vol, jname, B_FALSE, B_TRUE, NULL);

	return (snapshot_create(vol, jname, B_FALSE, B_TRUE));
}
Example #5
0
/*
 * Insert the backup snapshot name into the path.
 *
 * Input:
 * 	name: Original path name.
 *
 * Output:
 * 	name: Original name modified to include a snapshot.
 *
 * Returns:
 * 	Original name modified to include a snapshot.
 */
char *
tlm_build_snapshot_name(char *name, char *sname, char *jname)
{
    zfs_handle_t *zhp;
    char *rest;
    char volname[ZFS_MAXNAMELEN];
    char mountpoint[PATH_MAX];

    if (get_zfsvolname(volname, ZFS_MAXNAMELEN, name) == -1)
        goto notzfs;

    (void) mutex_lock(&zlib_mtx);
    if ((zlibh == NULL) ||
            (zhp = zfs_open(zlibh, volname, ZFS_TYPE_DATASET)) == NULL) {
        (void) mutex_unlock(&zlib_mtx);
        goto notzfs;
    }

    if (zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mountpoint, PATH_MAX, NULL,
                     NULL, 0, B_FALSE) != 0) {
        zfs_close(zhp);
        (void) mutex_unlock(&zlib_mtx);
        goto notzfs;
    }

    zfs_close(zhp);
    (void) mutex_unlock(&zlib_mtx);

    rest = name + strlen(mountpoint);
    (void) snprintf(sname, TLM_MAX_PATH_NAME, "%s/%s/%s%s", mountpoint,
                    TLM_SNAPSHOT_DIR, jname, rest);

    return (sname);

notzfs:
    (void) strlcpy(sname, name, TLM_MAX_PATH_NAME);
    return (sname);
}