General discussion

Locked

CP command with more options

By Lintadsl ·
I want to copy all home folder with sub-folders to /mnt/backup folder everyday at midnight. So, I used cp -R /home/* /mnt/backup/ command and make a script and put it in the cron. First night, it works. But second night, it did not work because it prompted for overwrite. I have used --force but still prompt for overwrite. How can I bypass for overwrite? I looked at the man for cp but did not help me.
I am using Redhat 7.3.
Thanks in advance.

This conversation is currently closed to new comments.

13 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

CP command with more options

by Ann777 In reply to CP command with more opti ...

Why not put a delete line in the script just before the copy? The files should be on backup tape the night before if anything crashes + you have the file in their original location if the script fails between the delete of the old and the copy ofthe new.

Collapse -

CP command with more options

by Ann777 In reply to CP command with more opti ...

Try a cp -f or a cp -i

I don't know if either will work in your flavor of unix.

Collapse -

CP command with more options

by Lintadsl In reply to CP command with more opti ...

cp -f would not work for me. Again, there are sub-folders and need to be copied as well.

Collapse -

CP command with more options

by pahosler In reply to CP command with more opti ...

cp -r --remove-destination /home/* /mnt/backup

or

cp -r --reply=yes /home/* /mnt/backup


cp --help will give you a complete list of options

Collapse -

CP command with more options

by Lintadsl In reply to CP command with more opti ...

Poster rated this answer

Collapse -

CP command with more options

by Skizz In reply to CP command with more opti ...

Use one of the archive type commands like tar or cpio.
tar will overwrite the backup each time it is run
tar -cvf /mnt/backup/my_backup.tar /home

Collapse -

CP command with more options

by Lintadsl In reply to CP command with more opti ...

Poster rated this answer

Collapse -

CP command with more options

by bwaynef In reply to CP command with more opti ...

Honestly I dont understand why your attempts have not worked. At the command line try typing:
cp -fR /home/* /mnt/backup. If this doesn't work I'd try adding the --remove-destination flag like this

cp -R --remove-destination /home/* /mnt/backup. Again, I believe all of these have been offered as possible solutions. None of these work? Try adding the --reply=yes flag and see if that works. It will basically reply "yes" to any prompt that is given, in effect giving permission to overwrite existing files in /mnt/backup.

Collapse -

CP command with more options

by Lintadsl In reply to CP command with more opti ...

Poster rated this answer

Collapse -

CP command with more options

by TG2 In reply to CP command with more opti ...

you are running it as root?

see if your distro allows

cp -af

-a == pdR / preserve no deference (don't follow symlinks just create a new symlink) and Recursive (but allow for fifo or /dev/null type files)

and also try puting the command as this

\cp -af /home /mnt/backup

the \ means to use the command without any modifications from the environment... or as I understand it to mean..

so if someplace the CP command is set to use "interactive" mode by default, then using the \will negate that setting and use the command straight again.

You'd be surprised where that little \ can come in handy by the way. It solved a sendmail on the command line problem we'd had sending email alerts from our solaris boxes.. by escapingthe command, the command line usage would then correctly allow other switches that weren't working without the \ before a sendmail command line, line.

Back to Linux Forum
13 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums