Submitted by zxeem on Mon, 25/07/2005 - 00:28.
( categories: )

Hi friends ,,

I need help .. I am created a very small script for backup in my PC .. but I am Lazy ...

this is the script !

rm -f backupfile.tar.gz & tar -czf backupfile.tar.gz --exclude=backupfile.tar.gz /home/name/ &

it creats .. a backup for my home .. but What i need is to complet the script .. so that it copies it to a restricted writing place that only root can write to .!!

I tried to

echo password > su

but it didn't work .. so if any can help .. I will be so greatful so that I can put this

cp backupfile.tar.gz /mnt/C/ &

zXeem *


Do you want to keep wite acce

Conceptor's picture

Do you want to keep wite access for root only and coping or tar got the privilage to write on your path.or you want to have write access genarlly to your path so every one could write on it

insted of using 2 commands tar then cp you could do it on tar :

rm -f backup.tar.gz && tar -czf /mnt/C/backup.tar.gz --exclude=backup.tar.gz /home/name/ 

Diaa Radwan

The --exclude has no place

ezabi's picture

The --exclude has no place in the context because it's already not in the source directory, the command would be:

rm -f /mnt/C/backup.tar.gz && tar -czf /mnt/C/backup.tar.gz /home/name/ 


Complain, do nothing, get your free Patagonian identity.

I am root

zxeem's picture

OKay . . EveryBody .. I am the root .. but using an ordinary account not the root account !!

what I need is not to know how to backup .. It already works .. with --exclude or without ...

what I really need is when writing a shell script .. that a user runs ... like what I am doing in the backup of my /home/name/ directory ! how to move to root privilige !!

how to use su in the shell script !!

Zxeem*

elaborate

Conceptor's picture

what is the device that mounted on /mnt/C ?

is it windows fat drive or it's windows ntfs drive or it's smb share (windows share) or nfs share (linux share) or it's an ext3 mount drive.

switch to super user (root) then type

visudo 

go to last line with arrows to the end of file then press "o"

add this line:

username        ALL= NOPASSWD: /bin/tar

press :wq hit enter it will quit.

exit from root shell then try this command

 sudo /bin/tar -czf /mnt/C/backupfile.tar.gz   /home/name/ 

give us the feed back.

Diaa Radwan

i used his command.

Conceptor's picture

i am focusing on it's not important to have tar then cp. i used the same command ,it does not make any sense to exclude non-existing file :)

Diaa Radwan

didn't work

zxeem's picture

this is the ouput I got (after edit visudo ) :

tar: Removing leading `/' from member names

tar: /mnt/c/encback.tar.gz: Cannot open: Permission denied

tar: Error is not recoverable: exiting now

Zxeem*

this is not clear

Conceptor's picture

try to send the what we have added on visudo (vi opens /etc/sudoers)

send also the executed command of tar.

Diaa Radwan

Here every thing !!!

zxeem's picture
  1. Host alias specification
  1. User alias specification
  1. Cmnd alias specification
  1. Defaults specification

Defaults targetpw # ask for the password of the target user i.e. root

%users ALL=(ALL) ALL # WARNING! Only use this together with 'Defaults targetpw'!

  1. Runas alias specification
  1. User privilege specification

root ALL=(ALL) ALL

zxeem ALL=(ALL) ALL

zxeem ALL= NOPASSWD: /bin/tar

  1. Uncomment to allow people in group wheel to run all commands
  1. %wheel ALL=(ALL) ALL
  1. Same thing without a password
  1. %wheel ALL=(ALL) NOPASSWD: ALL
  1. Samples
  1. %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
  1. %users localhost=/sbin/shutdown -h now

===================================== about the tar command !!

tar -czf /mnt/c/backup.tar.gz /home/zxeem/

so .. any suggestions !! ...

Zxeem*

try it now.

Conceptor's picture

1- remove this line from /etc/sudoers zxeem ALL=(ALL) ALL (you shouldn do ALL) .

2- when you use the full privileged tar command add sudo before it

sudo /bin/tar -czf /mnt/c/backup.tar.gz /home/zxeem/
.

Diaa Radwan

simple bash backup script

Pronco's picture

I've seen a rather complex bash script for backup, used to run it every day, it's really nice, it uses diff and send you a mail with the log


-I used to be indecisive .. but now I'm not so sure

Nice But ...

zxeem's picture

That is gr8 .. But I wanna ask .. does it make a backup for a user's home then put it in the /mnt/c ... that only root .. can edit :-|

If so .. then I will be gr8ful if u give me a link to one .. if not .. then hope . u think with us .. to recreat this backup script !!

Thank You

Zxeem*

edit

Pronco's picture

with little ease you should be able to modify the script I gave you the URL to do what you want.

just edit the variables in the script to fit in with the directories you want backed up and if necessary you can add in a function to make the backups read-only for all but root.

I've always considered writing my own because I never seem to find one that I consider perfect, the one I gave you is the best one I've found though.

If I ever sit down and write my own script I'll let you know


-I used to be indecisive .. but now I'm not so sure

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.