klintkrossa
Posts: 81
Joined: Tue Nov 10, 2015 3:06 pm

Can a raspberry pi backup/clone itself to a NAS?

Fri Feb 10, 2017 10:49 pm

Hello,
There is a lot like this question;
Can a raspberry pi backup/clone itself to a NAS?
What I eventual want to do then is make it into an .img file. So if there is a quick way to make an live .img file to the NAS that would be better.
I have found that I can mount to the NAS so I don't want a loop trying to load itself.


Klint
Thanks
This is not like any other bulletin boards that I have been on. Been flamed on other BB's so bad I was afraid to ask.

All my Raspberry Pi's are like the Hessian artilleryman of Sleepy Hollow.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Can a raspberry pi backup/clone itself to a NAS?

Sat Feb 11, 2017 12:01 am

You can do that with dd as long as you've got a NAS share mounted.

cd /shared/backups
sudo dd if=/dev/mmcblk0 of=$(hostname).$(date +%F).img bs=40M &


My NAS shares all use NFS not CIFS.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Can a raspberry pi backup/clone itself to a NAS?

Sat Feb 11, 2017 11:18 am

Whilst you can use dd to copy a mounted image it's almost certainly going to lead to an inconsistent filesystem as writes will still be happening whilst you're doing the backup. For a 32GB SD card dd'ing the image over the network is likely going to take an hour (maybe longer if it's being used).

A better option might be rsync which will work at the file level, There are options for rsync to tell it not to cross filesystem boundaries. Even this might lead to some file inconsistencies (particularly things like databases), but you can run rsync a few times in quick succession to get things that changed during the previous sync.

Restoring from an rsync image might be a bit more tricky, you would either need to create an image from the files. Alternatively you could stick a minimal image on an SD card and rsync the files back from the backup over the top of the minimal SD image.

Return to “Advanced users”