ZFS INCREMENTAL BACKUPS OVER SSH

Status
Not open for further replies.

Fei

Explorer
Joined
Jan 13, 2014
Messages
80
Hi

I want to use zfs send & recv to do incremental backup, and setting a auto-snapshot on receive side.

The script run full backup is normal , but when it run the incremental backup ,it always destroy my auto-snapshot. :(

I think this problem is time ssh root@$host zfs send -R -i $snapshot_latest $snapshot_current | zfs recv -Fv $destination , but I dont know how to modify it.

The sending side always keep 1 snapshot,because I don't want to use the sending side much space.
so when script done,it will destroy previous snapshot and keep current snapshot.

<my script>
Code:
snapshot_current="$pool@"`date "+%Y-%m-%d-%H-%M"`
snapshot_latest="$pool@latest"
if ssh root@$host zfs list -H -o name -t snapshot | sort | grep "$snapshot_latest$" > /dev/null; then
echo " latest snapshot, $snapshot_latest, exists lets proceed with backup"  >> /jobs/log/vrp.log 2>&1
time ssh root@$host zfs send -R -i $snapshot_latest $snapshot_current | zfs recv -Fv $destination >> /jobs/log/vrp.log 2>&1
echo " VRP Incremental Backup Complete "  >> /jobs/log/vrp.log 2>&1
ssh root@$host zfs destroy -r $snapshot_latest
ssh root@$host zfs rename $snapshot_current $snapshot_latest
exit 0
else
echo " missing latest snapshot aborting, $snapshot_latest"  >> /jobs/log/vrp.log 2>&1
time ssh root@$host zfs send $snapshot_current | zfs recv -Fv $destination >> /jobs/log/vrp.log 2>&1
echo " VRP Full backup complete "  >> /jobs/log/vrp.log 2>&1
ssh root@$host zfs rename $snapshot_current $snapshot_latest
exit 1
fi


<script log>
Code:
Wed May 20 10:41:34 CST 2015 VRP Start
taking current snapshot, vol/Customer_Environment@2015-05-20-10-41
latest snapshot, vol/Customer_Environment@latest, exists lets proceed with backup
attempting destroy vol/Customer_Environment@latest
success
attempting rename vol/Customer_Environment@2015-05-20-10-15 to vol/Customer_Environment@latest
success
attempting destroy vol/Customer_Environment@auto-20150520.1040-2w
success
receiving incremental stream of vol/Customer_Environment@2015-05-20-10-41 into vol/Customer_Environment@2015-05-20-10-41
Unsupported share protocol: 1.
received 153KB stream in 1 seconds (153KB/sec)
VRP Incremental Backup Complete
 
Last edited:

Robert Trevellyan

Pony Wrangler
Joined
May 16, 2014
Messages
3,778
I want to use zfs send & recv to do incremental backup, and setting a auto-snapshot on receive side.

The script run full backup is normal , but when it run the incremental backup ,it always destroy my auto-snapshot. :(

I think this problem is time ssh root@$host zfs send -R -i $snapshot_latest $snapshot_current | zfs recv -Fv $destination , but I dont know how to modify it.

The sending side always keep 1 snapshot,because I don't want to use the sending side much space.
so when script done,it will destroy previous snapshot and keep current snapshot.
According to the zfs man page, zfs receive -F will:
Code:
Force a rollback of the file system to the most recent snap-
shot before performing the receive operation. If receiving an
incremental replication stream (for example, one generated by
"zfs send -R -Fi -iI"), destroy snapshots and file systems
that do not exist on the sending side.

which would seem to explain the behavior you're seeing.

If the source side is so short of space that you can't afford to keep a few snapshots there, you should probably grow your storage.
 

Fei

Explorer
Joined
Jan 13, 2014
Messages
80
Hi Robert

I know root cause is ""zfs recv -F "" , so I modify zfs send -R -i $snapshot_latest $snapshot_current | zfs recv -Fv $destination to zfs send -i $snapshot_latest $snapshot_current | zfs recv -Fv $destination .

my job sample similar to this link https://db.tt/RivefRoI <--- zfs.ppsx
 

Robert Trevellyan

Pony Wrangler
Joined
May 16, 2014
Messages
3,778
I don't understand why you removed -R from the send instead of removing -F from the receive. But honestly, I've only ever done simple manual replication, never anything automated.
 

Fei

Explorer
Joined
Jan 13, 2014
Messages
80
If remove -F ,snapshot name will become random.
Code:
ssh root@$host zfs send -R -i $snapshot_latest $snapshot_current | zfs recv -v $destination


incremental test 1
Code:
[root@160nas] /jobs# zfs list -t snapshot |grep Custom
vol/Customer_Environment@latest                                            11.6K      -  1.43G  -
vol/Customer_Environment@2015-05-22-15-56                                      0      -  1.43G  -


incremental test 2
Code:
[root@160nas] /jobs# zfs list -t snapshot | grep Custom
vol/Customer_Environment@latest                                            11.6K      -  1.43G  -
vol/Customer_Environment@recv-90531-1                                      11.6K      -  1.43G  -    <----snapshot name become random
vol/Customer_Environment@2015-05-22-15-57                                      0      -  1.43G  -
 

Robert Trevellyan

Pony Wrangler
Joined
May 16, 2014
Messages
3,778
I see.

Unfortunately it seems to me you have conflicting requirements:
  1. Destination to match source.
  2. Source to keep only one previous snapshot.
  3. Destination to keep multiple snapshots.
It seems like 1 and 3 are in conflict.

To put it another way, the idea of ZFS replication is to faithfully clone a filesystem. When you take a snapshot at the destination, you're modifying the filesystem. Future replication jobs are bound to destroy that snapshot, because that's what it means to make a faithful clone of the source (snapshots are an integral part of the filesystem).

Perhaps in your case, rsync from source to destination with snapshots at the destination would be a better solution.

EDITED for clarity.
 
Status
Not open for further replies.
Top