Showing posts with label Backup. Show all posts
Showing posts with label Backup. Show all posts

How To Backup Remote Linux Host Using rsnapshot rsync Utility

0 comments

In the previous article we reviewed how to backup local unix host using rsnapshot utility.


In this article, let us review how to backup remote Linux host using this utility.




1. Setup Key Based Authentication


As we’ve explained earlier setup the key based authentication as explained either in ssh-keygen and ssh-copy-id article or openSSH article.



[root@local-host]# ssh-keygen

[root@local-host]# ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

2. Verify the password less login between servers


Login to the remote-host from local-host without entering the password.



[root@local-host]# ssh remote-host
Last login: Sun Mar 15 16:45:40 2009 from local-host

[root@remote-host]#

3. Configure rsnapshot and specify Remote Host Backup Directories


Define your remote-host destination backup directories in /etc/rsnapshot.conf as shown below. In this example,




  • root@remote-host:/etc – Source directory on the remote-host that should be backed-up. i.e remote backup destination directory.

  • remote-host-backup/ – destination directory where the backup of the remote-host will be stored. Please note that this directory will be created under local-host /.snapshots/{internal.n}/ directory as shown in the last step.


# vi /etc/rsnapshot.conf

backup root@remote-host:/etc/ remote-host-backup/ exclude=mtab,exclude=core

4. Test rsnapshot Configuration


Perform configuration test to make sure rsnapshot is setup properly and ready to perform Linux rsync backup.



# rsnapshot configtest
Syntax OK

5. Add Crontab Entry for rsnapshot


Once you’ve verified that the rsync hourly and daily backup configurations are setup properly in the rsnapshot cwrsync utility, it is time to set this puppy up in the crontab as shown below.



# crontab -e
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily

Check out Linux crontab examples article to understand how to setup and configure crontab.



6. Manually test the remote-host backup once


[root@local-host]# /usr/local/bin/rsnapshot hourly

[root@local-host]# ls -l /.snapshots/hourly.0/
total 8
drwxr-xr-x 3 root root 4096 Jul 22 04:19 remote-host-backup
drwxr-xr-x 3 root root 4096 Jul 13 05:07 localhost

[root@local-host]# ls -l /.snapshots/hourly.0/remote-host-backup/
total 4
drwxr-xr-x 93 root root 4096 Jul 22 03:36 etc

Troubleshooting Tips


Problem: rsnapshot failed with ERROR: /usr/bin/rsync returned 20 as shown below.



[root@local-host]# /usr/local/bin/rsnapshot hourly
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(260)
[receiver=2.6.8]
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: /usr/bin/rsync returned 20 while processing copyman@192.168.2.2:/etc/

Solution: This typically happens when the users who is performing the rsnapshot (rsync) doesn’t have access to the remote directory that you are trying to backup. Make sure the remote host backup directory has appropriate permission for the user who is trying to execute the rsnapshot.

Perform SSH and SCP Without Entering Password on openSSH

0 comments

In this article, I’ll explain how to perform ssh and scp without entering the password using the SSH Public Key authentication with SSH Agent on openSSH


There are two levels of security in the SSH key based authentication. In order for you to login, you need both the private key and the passphrase. Even if one of them is compromised, attacker still cannot login to your account, as both of them are needed to login. This is far better than typical password based authentication, where if the password is compromised, attacker can gain access to the system.


There are two ways to perform ssh and scp without entering the password:




  1. No passphrase. While creating key pair, leave the passphrase empty. Use this option for the automated batch processing. for e.g. if you are running a cron job to copy files between machines this is suitable option.

  2. Use passphrase and SSH Agent. If you are using ssh and scp interactively from the command-line and you don’t want to use the password everytime you perform ssh or scp, I don’t recommend the previous option (no passphrase), as you’ve eliminated one level of security in the ssh key based authentication. Instead, use the passphrase while creating the key pair and use SSH Agent to perform ssh and scp without having to enter the password everytime as explained in the steps below.


Following 8 steps explains how to perform SSH and SCP from local-host to a remote-host without entering the password on openSSH system



1. Verify that local-host and remote-host is running openSSH


[local-host]$ ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

[remote-host]$ ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

2. Generate key-pair on the local-host using ssh-keygen


[local-host]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):<Hit enter>
Enter passphrase (empty for no passphrase): <Enter your passphrase here>
Enter same passphrase again:<Enter your passphrase again>
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
31:3a:5d:dc:bc:81:81:71:be:31:2b:11:b8:e8:39:a0 jsmith@local-host

The public key and private key are typically stored in .ssh folder under your home directory. In this example, it is under /home/jsmith/.sshd. You should not share the private key with anybody.


By default the ssh-keygen on openSSH generates RSA key pair. You can also generate DSA key pair using: ssh-keygen -t dsa command.



3. Install public key on the remote-host.


Copy the content of the public key from the local-host and paste it to the /home/jsmith/.ssh/authorized_keys on the remote-host. If the /home/jsmith/.ssh/authorized_keys already has some other public key, you can append this to the end of it. If the .ssh directory under your home directory on remote-host doesn’t exist, please create it.



[remote-host]$ vi ~/.ssh/authorized_keys 
ssh-rsa ABIwAAAQEAzRPh9rWfjZ1+7Q369zsBEa7wS1RxzWR jsmith@local-host

In simple words, copy the local-host:/home/jsmith/.ssh/id_rsa.pub to remote-host:/home/jsmith/.ssh/authorized_keys



4. Give appropriate permission to the .ssh directory on the remote-host.


[remote-host]$ chmod 755 ~/.ssh
[remote-host]$ chmod 644 ~/.ssh/authorized_keys

5. Login from the local-host to remote-host using the SSH key authentication to verify whether it works properly.


[local-host]$ <You are on local-host here>

[local-host]$ ssh -l jsmith remote-host
Enter passphrase for key '/home/jsmith/.ssh/id_rsa': <Enter your passphrase here>
Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102
No mail.

[remote-host]$ <You are on remote-host here>

6. Start the SSH Agent on local-host to perform ssh and scp without having to enter the passphrase several times.


Verify whether SSH agent is already running, if not start it as shown below.



[local-host]$ ps -ef | grep ssh-agent
511 9789 9425 0 00:05 pts/1 00:00:00 grep ssh-agent

[local-host]$ ssh-agent $SHELL

[local-host]$ ps -ef | grep ssh-agent
511 9791 9790 0 00:05 ? 00:00:00 ssh-agent /bin/bash
511 9793 9790 0 00:05 pts/1 00:00:00 grep ssh-agent

7. Load the private key to the SSH agent on the local-host.


[local-host]$ ssh-add
Enter passphrase for /home/jsmith/.ssh/id_rsa: <Enter your passphrase here>
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

Following are the different options available in the ssh-add:




  • ssh-add <key-file-name>: Load a specific key file.

  • ssh-add -l: List all the key loaded in the ssh agent.

  • ssh-add -d <key-file-name>: Delete a specificy key from the ssh agent

  • ssh-add -D: Delete all key


8. Perform SSH or SCP to remote-home from local-host without entering the password.


[local-host]$<You are on local-host here>

[local-host]$ ssh -l jsmith remote-host
Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102
No mail.
<ssh did not ask for passphrase this time>
[remote-host]$ <You are on remote-host here>

How to tar backup on tape through ssh

0 comments

# tar -cvzf /www | ssh root@station.domain.com "cat > /backup/www.tar.gz"


OR


# tar zcvf - /www | ssh root@192.168.1.101 "cat > /backup/www.tar.gz"


Output:



tar: Removing leading `/' from member names

/www/

/www/n/xx.in/

/www/c/zasx.asd/

....

..



You can also use dd command for clarity purpose:


# tar cvzf - /www | ssh root@192.168.1.101 "dd of=/backup/www.tar.gz"


It is also possible to dump backup to remote tape device:


# tar cvzf - /www | ssh ssh root@192.168.1.101 "cat > /dev/st0"


OR


you can use mt to rewind tape and then dump it using cat command:


# tar cvzf - /www | ssh ssh root@192.168.1.101 $(mt -f /dev/st0 rewind; cat > /dev/st0)$


You can restore tar backup over ssh session:


# ssh root@192.168.1.101 "cat /backup/www.tar.gz" | tar zxvf -

Mount NTFS drive from boot

0 comments
So, looks like you want to mount /dev/hda1 & /dev/hdb2. Edit /etc/fstab from a terminal with

Code:

gksudo gedit /etc/fstab

and add these two lines to the end of it.

Code:

/dev/hda1   /media/hda1   ntfs-3g   defaults   0   0

/dev/hdb2   /media/hdb2   ntfs-3g   defaults   0   0

Save it and close down gedit editing window. Then, install ntfs-3g driver, create those two new mount points, and mount them.

Code:

sudo apt-get update

sudo apt-get install ntfs-3g

sudo mkdir /media/hda1 /media/hdb2

sudo mount -a

df -h

Two two ntfs partitions will be mounted to /media/hda1 & /media/hdb2 from now on, every time you boot Ubuntu.

Labels: mount NTFS on linux

So, looks like you want to mount /dev/hda1 & /dev/hdb2. Edit /etc/fstab from a terminal with

Code:

gksudo gedit /etc/fstab

and add these two lines to the end of it.

Code:

/dev/hda1   /media/hda1   ntfs-3g   defaults   0   0

/dev/hdb2   /media/hdb2   ntfs-3g   defaults   0   0

Save it and close down gedit editing window. Then, install ntfs-3g driver, create those two new mount points, and mount them.

Code:

sudo apt-get update

sudo apt-get install ntfs-3g

sudo mkdir /media/hda1 /media/hdb2

sudo mount -a

df -h

Two two ntfs partitions will be mounted to /media/hda1 & /media/hdb2 from now on, every time you boot Ubuntu.

Windows Data Backup on Linux Server

0 comments
Windows Data Backup on Linux Server I had a work to take backup of Windows Data Server on my Linux based backup server.

As a user, i never tried for such kind of things specially merging the data of two different platforms. Mostly services offered by the Windows are different from Linux. In Win XP, could not find a suitable service to backup and synchronization of data on live server.

I tried many Open Source utilities like Cygwin, Amanda Backup etc. These are very hectic and needs a lot of hardware involvement and requires a lot of settings.

One of my friends suggested me to try SyncBack at least once.

Its amazing, all the things which i needed found and works, in a very simple graphical settings.

For further queries, please contact me on mail id

Restoring a backup in Webmin

0 comments
Restoring a backup in Webmin

If you find that a config file on your system has been corrupted, incorrectly edited or mistakenly deleted, it can be easily restored using this module.

The steps to perform a restore are :

Click on the Restore now tab.

Select the module or modules whose config files you want to restore from the Modules to restore menu.

In the Restore from section, enter the path to a local or remote file that was originally created by this module.

To be useful, it must contain backups for the modules that you selected above.

Click the Restore Now button.

If all goes well, a page will be displayed showing the number of modules and files restored.

Files will be restored to their original locations on the system, rather than the paths that are set on the Module Config pages of the selected modules.

Restoring a backup in Webmin

If you find that a config file on your system has been corrupted, incorrectly edited or mistakenly deleted, it can be easily restored using this module.

The steps to perform a restore are :

Click on the Restore now tab.

Select the module or modules whose config files you want to restore from the Modules to restore menu.In the Restore from section, enter the path to a local or remote file that was originally created by this module.

To be useful, it must contain backups for the modules that you selected above.

Click the Restore Now button.

If all goes well, a page will be displayed showing the number of modules and files restored.

Files will be restored to their original locations on the system, rather than the paths that are set on the Module Config pages of the selected modules.

RSYNC to backup your home DIR from your OLD server to New

0 comments

rsync -vrplogDtH –exclude=virtfs/ –progress -e ssh root@old-server-ip-address:/home/ /home/



g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? - ?Ú?????«?

g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? ?Ú?????

«g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? - ?Ú?????«?


Potential backup issues on servers with disabled /bin/tar

0 comments
It has been brought to our attention that backups are not running
properly on servers that have disabled /bin/tar. To eliminate this issue before
it becomes a problem please check the following:

Permissions on /bin/tar should be 755. This can be accomplished from
a root shell via the following command:
root@host [~]# ls -l /bin/tar

If the result of that command starts as follows you are all set and
everything should be working:

-rwxr-xr-x

If not, please execute the following command:
root@host [~]# chmod 755 /bin/tar

Cpanel manual backup

0 comments

/scripts/pkgacct username


Instantly runs a backup for any account.

Rsync

0 comments

rsync –delete –stats -vae ssh 66.249.137.130:/backup/cpbackup/daily/ /backup/cpbackup/daily/ –exclude-from ‘/root/exclude.txt’


I added the file exclude.txt because with this code you can have certain files not be transferred. In this case I added pending and spam emails.


So my exclude.txt file has this in it:


*.*.dwhs1234.dwhs.net


*.*.dwhs1234.dwhs.net:2,


*.*.dwhs1234.dwhs.net:2,*


*.msg”
core.*
*.*.mbox:2,


This is for a cpanel based server.

Backing Up/Restoring Mysql Databases using SSH/Shell

50 comments

This is really the most handy tool for mysql databases. A built in mysqldump can be used via shell to dump mysql databases within a few minutes. Sometimes dumping backups using phpmyadmin is too hazardous. So it’s really a necessary tool and fast too. I have listed this commands and i believe this should be useful to lots of system admins



Taking Database Backup
mysqldump -uuser -pmysqluserpassword database_name > database_name.sql

Restoring a Database
mysql -uuser -pmysqluserpassword database_name < database_name.sql

Here, you need to replace the user with the proper database user who has access to that specific database and the mysqluserpassword directs the password of that specific user. Here, one important thing is database_name.sql file can be replaced with the location of the sql file, suppose if you want to save it or retrieve from /home/backup then you can put /home/backup/database_name.sql to do that.

Error while restoring cPanel backup

47 comments

Error :


Sorry, a group for that username already exists.


Fix :


User account related information is stored in /etc/passwd/etc/shadow and /etc/group files . Check all of them and remove the entries.


You can remove the group by using:


groupdel groupname


And then restore the account.


You can also restore the account forcefully by using :


/scripts/restorepkg –force username