1#Backup using mysqldump & zip SFTP client.
export mysqldump
zip www directory & server config files
download to local computer
upload
& configuration files & Data
assign users from root to server user.
remote transfer between two linux servers ,rsync
#2 SCP: copying files & directories one sever to another server remote
scp command
secure copy,
scp source user@destinationip: pathtosave
1) If we want to copy a file from a local machine to a remote machine:
syntax:
scp [file_name] remoteuser@remotehost:/remote/directory
2) If we want to copy a file from remote machine to our local machine.
syntax:
scp user@remotehost:/home/user/file_name .
scp /var/www/bak.zip root@192.168.0.1: /var/www/
or just delete the html directory in new server
scp -r /var/www/html root@192.168.0.1 /var/www/html
3rd or copying only internal file of html
scp -r /var/www/html/* root@192.168.0.1 /var/www/html
asks for password enter root password.
# 1. Enable roor login in Linxu serer
incase ssh disabled root login. enable root login
in sshd.config file
and
restart sshd.
enable disable password login
nano /etc/ssh/sshd_config
take backup cp
passwordauthentication yes/no
#comment
allow root password login yes/no
#comment
service ssh restart
Incase of Portnumber change
The default port is 22 if nobody changed configuration in the sshd_config file. You may also just append the port number after the host IP address.
2nd way
ssh-copy-id command
ssh-copy-id user@remoteip
enter password.
next time
ssh user@remoteip
login successful
no manual copying
for one-time use its better to use ssh password
once the file copied you can disable root login.
to avoid brute force attacks
or pairing ssh keys between two remote severs
public key source machine
private key in target machine
type scp to know manual page(command options)
scp -p22 /,pathtopublickey
#3 Rsync (remote sync data to local & remote to remote)
data between two servers syncs.
set a chrome job to backup daily/weekly.
apt install rsync
syncing data (1st time) to backup directory
rsync datadirectory/* /backupdir
rsync -r /var/www/html/ /etc/home/backup/
-r recursively subfolder & files
-a with users & file permissions attributes .files /hidden files
-av
v verbose output
rsync root@remoteip:- /path/tosave /currentserverpath
File Transfer rsync /scp
Rsync web root Directory
rsync -avz –progress 111.222.333.444:/var/www/site1 /var/www/
Rsync the apache conf
rsync -avz –progress 111.222.333.444:/etc/apache2/* /etc/apache2/
Rsync php config file
rsync -avz –progress 111.222.333.444:/etc/php5/* /etc/php5/
Rsync mysql conf
rsync -avz –progress 111.222.333.444:/etc/mysql/* /etc/mysql/
remote file deleted / source file deleted both will lost.
if new file added both gets new.
ssh root@111.222.333.444 ‘mysqldump -a -u root -ppassword > /root/alldb.sql’
-A dump all databases.
syncing to current server
rsync -avz –progress 111.222.333.444:/root/alldb.sql /root/
import
mysql -u root -ppassword < /root/alldb.sql
rsync is the best Backup solution on server for daily/weekly/monthly routines
#1.1 pairing two servers with ssh key (Optional)
with password
ssh user@remoteip
enter password
you done..
(but every time password entry, vulnerable to others.)
generating ssh keys
note: if you already have public in local desktop,
just copy another remote server, private key already at destination server.
or follow this
generating ssh key
ssh-keygen rsa -a -b 2048
or
ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa ssh-keygen -t ecdsa -b 521 ssh-keygen -t ed25519
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
ls -l /root/.ssh/
cat /root/.ssh/id_rsa.pub
adding public key to the Destination server which one connect
nano ./ssh/authorizedkeys not exost sometims
cd ./ssh
ls -la
copying public key to remote machine
scp (if root password login enabled or download & upload)
scp rsa.pub user@remotep: /pathtolocation
enter password
add public key to
./ssh/authorizedkeys
cat command (appends to end of the file)
file permissions
ssh folder 700
ssh files 600
chmod 700 ./ssh
chmod 600 ./ssh/*
Os kernel version & architecture
uname -r && uname -m
5.2.0-24-virtual
//Kernel version
Os architecture
X86_64 64bit
I686 32
distribution /os version
cat /etc/issue or lsab-release
Ubuntu 12.04.2 LTS \n \l
transfer ssh keys between two servers
transferring core data
/etc/sources/apt/list.deb
file & directories & MySQL dump
preparation
to check which services are running
service –status-all
connecting 2 servers ssh keys
cloning operating system to another disk
(windows desktop we use minitool,)
Migrating users & group
clone running linux server
another way.
cloning is to disk.
also read Linux performance tuning
Faqs
how to connect from one server to another server in linux
ssh [username]@[server IP]
root@ubuntu-s-2vcpu-4gb-intel-blr1-01:~# ssh root@159.65.149.73
root@159.65.149.73: Permission denied (publickey).
root@159.65.149.73: Permission denied (publickey).
cd ~/.ssh
root@murali:~/.ssh# nano authorized_keys
on source server
cat /root/.ssh/id_rsa.pub
root@murali:~/.ssh# service ssh restart