# Backing up ZFS pool to an external HDD



## ilemur (Sep 25, 2014)

I am currently running a RAID-Z (istorage) of 4*2 TB HDDs. There is one filesystem which I need to backup (istorage/storage) to external 3 TB HDD (it will fit). I have found some instructions on FreeNAS community but would like to use bookmarks which were introduced later in FreeBSD ZFS and use weekly snapshots I use currently. 

The original instructions were:
Backing up first time
`zfs snapshot -r istorage/storage@backup # create a snapshot`
`zfs send -R istorage/storage@backup | zfs receive -vF backup_hdd # transfer it over`

Then every time to increment

`zfs rename -r istorage/storage@backup istorage/storage@previous_backup # rename the "old" snapshot`
`zfs snapshot istorage/storage@backup # take a new snapshot`
`zfs send -Ri istorage/storage@previous_backup istorage/storage@backup | zfs receive -v backup_hdd # incremental replication`
`zfs destroy -r istorage/storage@previous_backup # get rid of the previous snapshot`


As I already have automatic weekly snapshotting set up can I start like (there are snapshots from week 20 to 25 present)
`zfs send -R istorage/storage@week25 | zfs receive -vF backup_hdd`

And then two weeks lately do
`zfs send -RI istorage/storage@week27 | zfs receive -v backup_hdd # incremental replication`

How can bookmarks help in this scenario?


----------



## usdmatt (Sep 25, 2014)

Your two commands listed at the end of the post don't appear correct. You don't specify a 'source' snapshot for your incremental send, and if you're only backing up one file system, you don't really need the `-R` option. Also, I'd recommend backing up to a child dataset on your backup pool, rather than to the root.

First backup:

```
zfs send istorage/storage@week25 | zfs recv backup_hdd/storage
```

Next:

```
zfs send -i week25 istorage/storage@week26 | zfs recv backup_hdd/storage
```

In the example above, once the week26 snapshot has been sent over, you can safely delete the week25 snapshot on both pools if you want. However, in order to be able to do an incremental backup next time, you need to keep the week26 snapshot on both pools. (It will be the 'source' snapshot in the next send):

Week 27:

```
zfs send -i week26 istorage/storage@week27 | zfs recv backup_hdd/storage
```

In your case I don't really see bookmarks being much use, in fact I sometimes wonder why they went through the effort of developing them.
Lets say for example that you've just done your week27 backup, and have made a large number of changes on your main pool, causing you to start running out of space. You could free up a load of space by deleting the week27 snapshot, but you need that snapshot in order to be able to do an incremental backup next week. With bookmarks you can do the following:


```
# zfs bookmark istorage/storage@week27 week27-bookmark
# zfs destroy istorage/storage@week27
```
(Disclaimer: I've never used bookmarks and I'm not sure if that syntax is correct)

You've now destroyed that snapshot, freeing up any space it was using. Next time you do an incremental send, you can use the bookmark as the source. (I'm not sure if you need to create a bookmark on both sides, or if ZFS is clever enough to match it up with the week27 snapshot on the backup pool)

As long as you have enough space to keep the last backup snapshot around on both pools, I can't see bookmarks giving you any benefit.


----------



## Sebulon (Sep 26, 2014)

Hi @ilemur!

If you´d like to skip the scripting part, I´ve already written this tool that does exactly what you´re after:
replicate - Initial and continous ZFS filesystems replication

/Sebulon


----------

