is there a way to backup image of system without taking out SD card directly in Raspbian. For example on network drive like NAS or on USB-Flash?
Also one wish: image must be compressed, i mean - the size of image must be not the total size of SD card (for example 64Gb) but only the actual size of the Raspbian with all files (for example 2-6Gb) so if something fails i can write image again on another SD card and start system, without any installations?
No, because Linux is a multi-user system with processes always changing files.
You should only need your application, configuration, & data files anyway. It is usually preferred to install the OS fresh.
which gives me a compressed zipped backup of the whole SD card.
You just need to make sure that the user openhabian has NOPASSWD rights to /bin/dd in your sudoer file. If something goes wrong this image can be written back to the SD card - not remotely though - and all is up and running again.
@thisisIO one more thing: What @Bruce_Osborne said does apply to this backup method, if you want an exact copy of a specific point in time, you either need a filesystem that supports snapshots or remove the card and make an image. But this should still be good enough to get you up and running again.
Using rsync should be a lot faster, especially for incremental backups and less error-prone.
So this script https://github.com/lzkelley/bkup_rpimage is not sensible to running system?
Is it an image, that i can easy write on new SD (for example in windows with balenaEtcher) and put in raspi and it will work? Or is there other way to restore this backup?
A quick glance at the script seems to indicate that it also uses dd for the initial image creation. It also indicates the same as we have talked about here: " The backup is taken while the system is up, so it’s a good idea to stop programs and services which modifies the filesystem and needed a consistant stateof their file."
That’s not easy to answer. If you’re backing up to the same image every day you might backup files that are already corrupted without noticing it, for example. A proper backup solution will store a history of files and should allow you to go back to a working state.
It’s a sparse file. If your file system supports sparse files, the size of the image will depend on the actual content. So if you’re using 4GB of a 16GB card, the image will be around 4GB.