Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Full system backup with rsync in linux

This command depends on brace expansion available in both the bash and zsh shells. When using a different shell--exclude patterns should be repeated manually.
# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder
Using the -aAX set of options, the files are transferred in archive mode, ensuring that symbolic links, devices, permissions and ownerships, modification times, ACLs and extended attributes are preserved.
The --exclude option will cause files that match the given patterns to be excluded. The contents of /dev/proc/sys/tmp and /run were excluded because they are populated at boot (while the folders themselves are not created), /lost+found is filesystem-specific. Quoting the exclude patterns will avoid expansion by shell, which is necessary e.g. when backing up over SSH.
Note:
  • If you plan on backing up your system somewhere other than /mnt or /media, do not forget to add it to the list of exclude patterns to avoid an infinite loop.
  • If there are any bind mounts in the system, they should be excluded as well, so that the bind mounted contents is copied only once.
  • If you use a swap file, make sure to exclude it as well.
  • Consider also if you want to backup the /home/ folder. If it contains your data, it might be considerably larger than the system. Otherwise consider excluding unimportant subdirectories such as /home/*/.thumbnails/*/home/*/.cache/mozilla/*/home/*/.cache/chromium/*/home/*/.local/share/Trash/*, depending on software installed on the system. If GVFS is installed, /home/*/.gvfs must be excluded to prevent rsync errors.

How to disable firewall on RHEL / CentOS / RedHat Linux

First login as the root user.
Next enter the following three commands to disable firewall.
# service iptables save
# service iptables stop
# chkconfig iptables off
If you are using IPv6 firewall, enter:
# service ip6tables save
# service ip6tables stop
# chkconfig ip6tables off

Linux rdesktop ERROR recv Connection reset by peer

The vast majority of it means "Turn off Remote Desktop with NLA".
Set on target "Microsoft Windows (WIN)"
  1. run SystemPropertiesRemote.exe
  2. Deselect "Allow connections only from computers running Remote Desktop with NLA"
  3. Try to connect from linux client

Changing SSH Port in Linux

Open ssh config with your favorite editor:
vi /etc/ssh/sshd_config
Look for line with “Port 22”, should be on top:
_ # What ports, IPs and protocols we listen for Port 12345_
Restart ssh service:
/etc/init.d/ssh restart

******************SAUDI APPS DBA***************************************

Migrate MySQL Databases, Users, and Privileges to Different Server

1.) Databases:
  • Get list of databases
1
mysql -uroot -proot_password -e "show databases"
  • Dump all databases
1
mysqldump -uroot -proot_password --all-databases > databases.sql
Note: you can dump only the databases that you want to move. Also, you need to exclude the “mysql” database itself if you are moving into an mysql server with existing records.
* Transfer sql dumps to new server with your preferred way (ftp, scp, rsync, etc)
  • Create Databases on new server.
1
mysql -uroot -proot_password -e "create database database_name_1;"
1
mysql -uroot -proot_password -e "create database database_name_2;"
1
mysql -uroot -proot_password -e "create database database_name_3;"
  • Import database dumps to new server
1
mysql -uroot -proot_password < databases.sql
2.) Database Users and Privileges:
  • Get list of database users and their privileges.
1
mysql -B -N -uroot -proot_password -e "SELECT user, host FROM user" mysql
  • Then get the privileges and password hash for each users from the above step.
1
mysql -B -N -uroot -proot_password -e "SHOW GRANTS FOR 'db_user'@'db_host'"
Note: Above command will output similar to these two lines or you will get more if the db_user has access to more than one databases.
1
GRANT USAGE ON *.* TO 'db_user'@'db_host' IDENTIFIED BY PASSWORD '*23AW9301879BCC8BC24343CDCDC40F375606C43D'
1
GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'db_host'
  • Then you need to execute all these lines or queries on the new MySQL server. You can put them all in a text file (example: users.txt) and add semi-colon on each line, then import to mysql (example below):
1
mysql -uroot -proot_password < users.txt

HowTo Change Hostname in Linux

To check for current hostname:

1
hostname
Change hostname
1
hostname new_hostname
Make change permanent on reboot:
  • Debian/Ubuntu: edit or make changes on this file /etc/hostname
  • RHEL/CentOS: edit or make changes on this file /etc/sysconfig/network
Important:
Make sure to check or update new hostname in /etc/hosts as some running application could be using hostname values in there. Test running applications as well or try to reload/restart if possible (ex: apache).

Find out CPU, Memory, and Hard-disk information in Linux

Check for CPU/processor info and count:
>
cat /proc/cpuinfo | grep processor
Notes: Counting starts at 0. If the last processor id is 3 obviously you have 4 cpu cores. You can grep for “physical id” (ex: cat /proc/cpuinfo | grep “physical id”) to find out if cpus are virtual or not. If no physical id I think those are virtual cpu cores.
Check for total memory and usage. This also includes detail of swap memory:
>
free -m
Notes: ”-m” gives you the result in MB.
Check for hard drive space and usage:
>
df -h
Notes: ”-h” means human readable for size such as MB or GB, etc.
******************************SAUDI APPS DBA****************************************************

Step by step migration of schemas from Windows server Oracle10g Database to Linux Oracle 11g Database

Migration from SOURCEDB1 to TARGETDB1:
--------------------------------------

I'm going to use Datapump for migrating from SOURCEDB1(Oracle 10g) to TARGETDB1(Oracle 11g) Database.


General information:
---------------------


Source:
---------

OS version: Windows Server 2003 R2
Database version:10.2.0.4.0
Database size:33 GB


Target:
---------

OS version:RHEL 5.4
Database version:11.2.0.1.0

SCHEMAS TO MIGRATE:TESTTOOL,TESTTOOLMIG,TESTTOOLQA,TESTD,TESTD_TEST,TEST3CNS,TESTHP,TEST_USR


STEP 1: CREATE USER FOR OUR MIGRATION PURPOSE WITH ENOUGH PRIVILEGES
------


SQL> create user MIGTEST
2 identified by MIGTEST;

User created.

SQL> grant dba to MIGTEST;


SQL> select name from v$database;

NAME
---------
SOURCEDB1 

SQL> alter user MIGTEST identified by welcome123;

User altered.

SQL> alter user MIGTEST default tablespace users;

User altered.


Grant succeeded.

Step 2: CREATE DIRECTORY FOR DATAPUMP
-------

Create one directory for Datapump and point it to a directory where we have to
keep our dump files of datapump
Note: This location of keeping dump files should have enough space.

Directory Creation:
-------------------

SQL> CREATE DIRECTORY SOURCEDB1_MIG AS 'D:\ACEDBMIG';

Directory created.

GRANT Permission:
-----------------

SQL> GRANT READ,WRITE ON DIRECTORY SOURCEDB1_MIG TO MIGTEST;

Grant succeeded.


VERIFYING THE LOCATION:
---------------------------

SQL> select *from dba_directories;

OWNER DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
---------------------------------------------------------------------
SYS SOURCEDB1_MIG
D:\SOURCEDB1 

STEP 3: EXPORT THE SCHEMAS WHICH WE WANT TO MIGRATE:
------------------

Here I'm create one parameter file for export where I'm specifying
schemas which I want to export.The details and usage of this parameter can
be obtained from command 'expdp help=y' and very much self explanatory.


a) create one parfile(.par):
----------------------------


mig_expdp_SOURCEDB1_12APR_2011.par:
________________________________

SCHEMAS=TESTTOOL,TESTTOOLMIG,TESTTOOLQA,TESTD,TESTD_TEST,TEST3CNS,TESTHP,TEST_USR
DIRECTORY= SOURCEDB1_MIG
DUMPFILE=mig1_expdp_SOURCEDB1_12APR_2011.dmp 
LOGFILE=mig1_expdp_SOURCEDB1_12APR_2011.log 
EXCLUDE=STATISTICS 
CONTENT=ALL 
JOB_NAME=mig_expdp_SOURCEDB1_12APR_2011
PARALLEL=2

b)Create one batch file(.bat):
----------------------------------


SOURCEDB1_MIG_12APR2011.bat:
__________________________

expdp MIGTEST/MIGTEST PARFILE=E:\TEST_work\SOURCEDB1 _MIG_UGALAXY\mig_expdp_SOURCEDB1_12APR_2011.par

We can execute the above batch file by double clicking it.Check the dump file location it
will be surely in the path 'D:\ACEDBMIG'(This is the path which you have used for creating
Datapump Directory).Check the log file for any errors or warnings.

STEP 4:COPY THE DUMPFILE FROM SOURCE DATABASE SERVER(WINDOWS) TO TARGET DATABASE SERVER(LINUX)
-------

For copying the dumpfile I used winscp to copy it to my windows machine and than transferred to linux target
server,however you can use ftp or any other technique.


STEP 5:CREATE THE DIRECTORY FOR THE DATAPUMP IMPORT:
------


create directory IMP_MIGRATE_UGALAXY as '/u04/UGALAXY/ACEDB_MIGRAT_DUMPS';

grant read,write on directory IMP_MIGRATE_UGALAXY to system;

STEP 6:IMPORT THE DUMP IN THE TARGET DATABASE:
------


The import scripts are:
-----------------------

vi impdp_job_Apr13_2011.sh

impdp system/manager DIRECTORY=IMP_MIGRATE_UGALAXY REMAP_SCHEMA=TESTTOOL:TESTTOOL,TESTTOOLMIG:TESTTOOLMIG,
TESTTOOLQA:TESTTOOLQA,TESTD:TESTD,TESTD_TEST:TESTD_TEST,TEST3CNS:TEST3CNS,TESTHP:TESTHP,TEST_USR:TEST_USR
DUMPFILE=MIG1_EXPDP_ACEDB_12APR_2011.DMP LOGFILE=MIG1_EXPDP_ACEDB_12APR_2011.log

To run impdp job:
------------------


nohup sh impdp_job_Apr13_2011.sh >a.out


Once the import is completed check the logfiles for errors and warnings.

STEP 7: Validation of Data:
------


Validating the Data: 
-------------------- 
Once the import is done successfully verify the object imported.Compare the Source and Target Databases: 


Source Database(Oracle 10g rel2): 
---------------- 
SQL>select count(*) from dba_objects where owner in('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');

Target Database(Oracle 11g rel2): 
---------------- 
SQL>select count(*) from dba_objects where owner in('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');


Check for the invalid objects in Target Database side: 
-------------------------------- 
SQL> select owner||' '||object_name||' '||status from dba_objects 
where STATUS='INVALID'; 


Compile the invalid object using the below script: 
------------------------------------------------- 

SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql 

Recheck again and compile:
---------------------------

SQL> select owner||' '||object_name||' '||status from dba_objects 
where STATUS='INVALID'; 


Comparison of privs:
----------------------


Source:
----------
1)Object privs:
------------------
select grantee||' '||owner||' '||table_name||' '||privilege from dba_tab_privs
where owner in('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');

2)System privs:
----------------
select grantee||' '||privilege from dba_sys_privs
where grantee in ('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');


Target:
------------

1)Object privs:
------------------
select grantee||' '||owner||' '||table_name||' '||privilege from dba_tab_privs
where owner in('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');

2)System privs:
----------------
select grantee||' '||privilege from dba_sys_privs
where owner in('('TESTTOOL','TESTTOOLMIG','TESTTOOLQA','TESTD','TESTD_TEST','TEST3CNS','TESTHP','TEST_USR');