Ubuntu IRC- Please review/correct this script

If you are curious to visit the IRC channel, visit here first

https://wiki.ubuntu.com/IrcGuidelines

Thanks for visiting from IRC #ubuntu-offtopic

I am a beginner with Linux Ubuntu, and I want a simple means
to back up my system occasionally.

I found a tar command at the following link:

http://ubuntuforums.org/showthread.php?t=35087

I tried it once and it seemed to work, except I had some trouble getting rights to access the file in / root. I THINK that the following commands will work for me without hurting my install.

I DID do some things with sudo Nautilus and a /var/Backup folder which I believe crashed my whole Ubuntu system, and I had to spend 7 hours re-installing it, which you may read about at this blog.

So, I really need someone who is experienced in Linux and script/bash commands to look at this and tell me if there is any danger.

I DID get the tar command which you see below to work once, and I managed to copy it to a DVD. I put the dvd in my second computer which is a Wubi Ubuntu install on top of windows, and it was able to open the tar, browse the folders, and extract some files from /Desktop.

I WOULD ALSO APPRECIATE THE CORRECT COMMAND TO SAFELY DELETE backup.tgz from / root

Thanks for looking and commenting!

enter TERMINAL

sudo su

tar cvpzf backup.tgz –exclude=/proc –exclude=/lost+found –exclude=/backup.tgz –exclude=/mnt –exclude=/sys –exclude=/media /

sudo cd /

sudo chmod 777 backup.tgz

sudo cp -p backup.tgz /home/bryan/Desktop/mytestfolder/

++++++

1.
I WOULD ALSO APPRECIATE THE CORRECT COMMAND TO SAFELY DELETE backup.tgz from / root
2.
>>> sudo rm /backup.tgz
3.

4.
Thanks for looking and commenting!
5.

6.
enter TERMINAL
7.

8.
### sudo su
9.
### This is silly for two reasons. First, ‘sudo -i’ is preferable to ‘sudo su’. Second, rather than putting sudo on every line of the script, just run the script itself with sudo.
10.

11.
# This will work, but using v (verbose) doesn’t really add value with this huge of a data set, and significantly impairs performance (the terminal can’t keep up), so I’d probably drop it.
12.
tar cvpzf backup.tgz –exclude=/proc –exclude=/lost+found –exclude=/backup.tgz –exclude=/mnt –exclude=/sys –exclude=/media /
13.
# Note that you are not specifying a target directory for backup.tgz to end up in here. As you’ve noticed, it’s helpful to have it somewhere that you’re not backing up, to avoid recursion.
14.

15.
sudo cd /
16.

17.
sudo chmod 777 backup.tgz
18.

19.
sudo cp -p backup.tgz /home/bryan/Desktop/mytestfolder/
20.

21.

22.
THUS, my recommendations:
23.
—————————————————————————————————-
24.
#!/bin/bash
25.
tar cpzf /backup.tgz –exclude=/proc –exclude=/lost+found –exclude=/backup.tgz –exclude=/mnt –exclude=/sys –exclude=/media /
26.
chmod 755 /backup.tgz
27.
ln -s /backup.tgz /home/bryan/Desktop/mytestfolder/
28.
—————————————————————————————————-
29.
Save as mybackupscript.sh
30.
chmod +x mybackupscript.sh
31.
Run with:
32.
sudo ./mybackupscript.sh

++++++++++

tonyyarusso: one quick question, what does this last line do — ln -s /backup.tgz /home/bryan/Desktop/mytestfolder/
[02:07] what is ln -s
[02:07] WilliamBuell: Create a symbolic link
[02:07] WilliamBuell: it creates a symbolic link
[02:07] symlink
[02:08] WilliamBuell: It makes a “pointer” of sorts in your home directory to the real file, rather than copying it all over.
[02:08] and, ok ln symbolic link, how is that useful
[02:08] can reach data 2 ways but only have it exist on disk once
[02:08] so, you are saying that when I mount a dvd, and go to file manager, i will SEE the tar in that folder (but it is really the symbolic link) and i may freely copy it to the dvd
[02:08] so if you dont want to type a really really long path, you can have a shortcut
[02:08] WilliamBuell: Half the disk space usage, and less time.
[02:08] WilliamBuell: yup
[02:09] wow, thanks, now it all makes sense
[02:09] there are also hardlinks (ln without the -s)
[02:09] what is difference between hard and soft link
[02:09] symlinks point to a path to the data so they can point to things on other disks/partitions/media

hardlink vs symlink

[02:19] WilliamBuell: I thought you wanted it in that folder for some kind of convenience – it’s certainly not necessary.
[02:19] oh, ok…. i am just scared to death of root, since my crash
[02:19] the script can go wherever you like. Many people like to create /home/bryan/bin/ for such things, but it doesn’t matter.
[02:20] so sudo ./mybackupscript.sh WILL SEARCH until it finds that file, wherever it is, even on /Desktop ?
[02:20] No.
[02:20] It will be the current working directory, whatever that is.
[02:21] oh, ok, so as long as i am in current directory where that .sh is, and i sudo ./ it will find the .sh
[02:21] but, i should not save the script to root, i take it
[02:22] and if i did create /home/bryan/bin i would cd to that, and then sudo ./mybackupscript.sh
[02:23] right
[02:23] but, if i went into gedit and saved some file as mytestfile.sh in root,… it would not harm root
[02:23] except it is a bad practice to store things in root

Advertisements

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: