Solved

Linux Commands for Remote Backup

Posted on 2016-10-10
5
48 Views
Last Modified: 2016-11-01
Hi

I'm looking to backup Raspberry Pi remotely to a NAS server. I am looking to use the following sequential commands :

sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/noip stop
sudo /etc/init.d/cron stop
sudo dd if=/dev/mmcblk0 of=/testnas01/backups/raspberryPiSDCardBackup.img
sudo /etc/init.d/cron start
sudo /etc/init.d/lighttpd start
sudo /etc/init.d/noip start
0
Comment
Question by:L-Plate
5 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 41837810
are you trying to backup to local storage or you want to backup to remote system?
0
 
LVL 47

Assisted Solution

by:dlethe
dlethe earned 250 total points (awarded by participants)
ID: 41837814
Do you have an actual question?    But i expect you want to take an image back up a Pi that is booted, and running networking services, AND has a read/write filesystem.

No. You can't do that.  (Well, you can, but the backup, then of course, the restore will be corrupted because you are changing files while backing up).

There are some Pi O/S variations that are pure read-only (/tmp is a ramfs).   Now if you had a read-only FS then you could wouldn't need to stop any services, and it would work because data files aren't changing ..  but then again if you had a read-only filesystem, then you wouldn't need to make frequent backups of it, since it doesn't change.
0
 
LVL 40

Accepted Solution

by:
noci earned 250 total points (awarded by participants)
ID: 41837968
Yes it will dump the mmc card to a remote location....
BEFORE doing dd... do

sync; sync; sync
sleep 5

Then at least all data is dumped to the card first. sleep a while to await dumping of data.
Best would be to do syn; sync; sync and remount all Filesystems as read only, but that will require stopping all services...
{ stop services }
sleep 5       # wait for lagging services
sync; sync; sync     # dump all memory buffers
sleep 5     # wait for last writes
mount -o remount,ro .....
{ dd }
mount -o remount,rw ....
{ start services }

Effectively the not saving of this data is what corrupted most MMC cards with the early raspbian systems that never did a sync, and turning off the device would destroy at least some of the data/structure on a disk.
(It still might).

A better option is create one writeable part of the filesystem that is mounted rw while the whole filesystem is mounted ro, and dismount that
part short before dd and remount after dd  much safer.
1
 
LVL 47

Expert Comment

by:dlethe
ID: 41865731
auto close initiated
0
 

Author Comment

by:L-Plate
ID: 41868217
Thanks for your time on this very sorry I did not get back to close off and allocate the points.

I ended up backing/restoring up the Linux box locally to a USB stick using Win32 from Sourceforge
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question