LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Bash: Backup a directory using cp or cpio? (http://www.linuxquestions.org/questions/programming-9/bash-backup-a-directory-using-cp-or-cpio-4175440374/)

Xeratul 12-06-2012 11:32 PM

Bash: Backup a directory using cp or cpio?
 
Hi,

The goal is simple, making a backup using simple bash tools (actually linux sys tools such as cp and cpio) for:

/harddrive => /backups/hardrive


I would be glad if a solution such as --delete could be proposed in order to mirror the current state of the /harddrive.

The aim is to avoid rsync use.

Would you have any simple solution that might be proposed?

thank you in advance

pan64 12-07-2012 12:40 AM

why do you want to avoid rsync? This is the "best" and knows perfectly what you need (why do you want to reinvent the wheel?)

theNbomr 12-07-2012 09:02 AM

If rsync is not allowed to be part of the solution, then the solution will probably be sub-optimal. Ergo, what are the bounds within which a solution is deemed acceptable? Taking the literal meaning of your requirements: 'simple bash tools' would mean using only bash built-in commands, which leaves a quite sparse universe of available tools.
In summary, you need to think about the problem and describe what you are really trying to do. I'm smelling homework here, when the optimal and simple answer cannot be part of the solution.

--- rod.

Xeratul 12-07-2012 09:32 AM

because sometimes I use boxes on the network that have not rsync.

If you run a busybox, there is no rsync.

I cannot hack the root to install a rsync.

Besides there is bash and cp/cpio.

orgcandman 12-07-2012 10:53 AM

http://www.debianhelp.co.uk/cpiocommand.htm

Literally my first google result from 'cpio backup'

Xeratul 12-08-2012 01:24 AM

Quote:

Originally Posted by orgcandman (Post 4844644)
http://www.debianhelp.co.uk/cpiocommand.htm

Literally my first google result from 'cpio backup'

sure but the aim would be to achieve a backup with deleting the files on the destination that are not anymore on the source.

It is indicated in the above text of this thread.

Quote:

Originally Posted by Xeratul (Post 4844259)

I would be glad if a solution such as --delete could be proposed in order to mirror the current state of the /harddrive.


theNbomr 12-08-2012 10:30 AM

Why not just install rsync to a place that doesn't require root privileges? If you're making backups, you must have enough disk quota to accommodate that. Otherwise, just delete all of the backup files, and re-copy the source to the backup destination? Does the backup have to be accessible as part of the filesystem, or can it be a data blob like a tarball, or cpio archive?

--- rod.

pan64 12-08-2012 02:34 PM

I think you do not need to "install" rsync, just copy it into your home and you can tell on the other side where can it be found.

theNbomr 12-08-2012 03:37 PM

Not all binaries are transportable in that way. The versions various libraries may not satisfy the linking loader. It should be true that any identical or very similar installations can run copies of the same binary.

--- rod.

Habitual 12-08-2012 04:42 PM

Quote:

/harddrive => /backups/hardrive
Really? The whole hard drive?

Xeratul 12-13-2012 11:25 PM

Quote:

Originally Posted by Habitual (Post 4845390)
Really? The whole hard drive?

not really. it was an example.

So there are actually no one interested to develop a bash backup code to sync with --delete option :(

--
Everyone use X11, KDE, and Rsync ;) where are the geeks ?

theNbomr 12-14-2012 08:01 AM

Geeks aren't generally interested in developing things that have already been done, unless they can raise the bar somehow. Writing, in bash, an application that already exists is unlikely to fit that description.
--- rod.

Habitual 12-14-2012 09:43 AM

Why are you using BusyBox? If the goal is to "using simple bash tools (actually linux sys tools such as cp and cpio)"
and BB doesn't have rsync, then I'd RUN to find an alternative to busybox.
Even a broke watch is right twice a day.

Quote:

the aim would be to achieve a backup with deleting the files on the destination that are not anymore on the source.
source what? Busybox seems to be a linux binary program.

No mention of tar...? Curious.
BB includes that.

Statements like "I cannot hack the root to install a rsync." don't help. Hack what root? Who's root?

Who's network resources are you messing with and do you have permission to [cpio|cp|tar|backup]?
Linux cpio Examples: How to Create and Extract cpio Archives (and tar archives)
How do I use cpio command under Linux
https://wiki.archlinux.org/index.php/Tar

Good Luck.

Xeratul 12-15-2012 10:34 PM

Forget Busybox.

It is amazing that people are so curious, trying to help, and do not stick what is aimed. (please do not take it personally)

The first post is indeed confusing, and can trigger lot of questions. I can definitely understand. This is human.

You find then an example to make it simple, and though they ask thousand questions why not to install rsync or install a debian that has rsync.

I have of course all permissions.

Let's give additional info; this might be easier to understand:

CPIO can be used to backup but it misses the "--delete" option. It creates well the new directories, but to sync it and delete the non-present files in target if there arent anymore in the source dir? For that you need to do it by hand. So why bash? Because you can use it almost everywhere. Some people are traveling, using different machines, ... and portability can sometimes be needed. Some people have not necessarily to seat daily in front of the same computer all their life. So "portability" (script portability) can be an issue for some people.



Quote:

Geeks aren't generally interested in developing things that have already been done, unless they can raise the bar somehow. Writing, in bash, an application that already exists is unlikely to fit that description.
Geeks or hackers do not necessarily use what already exists. If they are making a worm, they code it themselves. If they are sufficiently good enough and skilled, they rather like to use their own program, if they have the time and if needed/preferred. Geeks and hackers are often pioneers in some areas. So mostly they gotta code their own programs in most cases, or to be lucky that a project already exists (GIT,...) and then join it.
Since everyone is different, some rather use what exists other use their own tools.


The aim of this thread is to come to a bash script that can be an alternative to rsync for simple copy/move operations over a mounted sshfs/nfs/samba... It can of course be done on any platforms or machines since cpio is mostly everywhere. Rsync not.


I see that I will not get any reply here on Linuxquestions. I should google on bash forums.

Habitual 12-16-2012 07:19 AM

Quote:

...I see that I will not get any reply here on Linuxquestions. I should google on bash forums.
http://bashscripts.org/forum/viewfor...e93ba9c5638484 may offer some help.


All times are GMT -5. The time now is 02:42 PM.