Monday, 13 June 2011

Back up in LInux


The best tool to use for this is probably dump, which is a standard linux tool and will give you the whole filesystem. I would do something like this:

/sbin/dump -0uan -f - / | gzip -2 | ssh -c blowfish user@backupserver.example.com dd of=/backup/server-full-backup-`date '+%d-%B-%Y'`.dump.gz

This will do a file system dump of / (make sure you don't need to dump any other mounts!), compress it with gzip and ssh it to a remote server (backupserver.example.com), storing it in /backup/. If you later need to browse the backup you use restore:

restore -i

Another option, if you don't have access to dump is to use tar and do something like

tar -zcvpf /backup/full-backup-`date '+%d-%B-%Y'`.tar.gz --directory / --exclude=mnt --exclude=proc --exclude=tmp .

But tar does not handle changes in the file system as well.



rsync -arv /home/[username] [username]@[local ipaddress]:/media/[partition]/[laptop]



Mysql back up command

mysqlhotcopy' works only with some storage engines and hence is not as popular as 'mysqldump'. 'mysqlhotcopy'  is a perl script that comes with the mysql installation and as it is a perl script it requires the perl-DBD module installed, without which it won't work. It is a fast way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located. 'mysqlhotcopy' works only for backing up MyISAM and ARCHIVE tables. It runs on Unix and NetWare. It uses FLUSH TABLES, LOCK TABLES, and cp or scp to make a database backup.

mysqlhotcopy --user=root --password=<password> <database-name> <path-to-the-destination>
      [shell] mysqlhotcopy -u [username]  -p[password] [db_name_1]  ... [db_name_n]  [/path/to/backup_dir]
   ex.
      [shell] mysqlhotcopy -u root -pSecretPass blog /home/jatin/mysqlbackups/


Restoring the backup created from 'mysqlhotcopy'

Restoring  data is very easy. Copy the files from the backup directory to the /var/lib/mysql/<db> directory (or the datadir specified in your my.ini mysql configuration file) . In order to avoid any issues, stop the mysql before you restore (copy) the files. After you copy the files to the /var/lib/mysql/<db> start the mysql again.

Above we just looked at the most common scenario, mysqlhotcopy has many options which you can look at by either using

perldoc mysqlhotcopy


mysqldump :

Although mysqlhotcopy is best suited for MyISAM table, it is most likely that you would be using the InnoDB tables in your database Or may not have perl installed or simply want a logical (SQL) output for your database. This is where mysqldump can come handy. Lets look at this type of backup and restore method :

The simplest syntax is
   1.
      mysqldump -u root -p[password] [database_name]> [dump_file_name].sql

So lets say we want to get the dump of our 'blog' database, we would use the following command
   1.
      mysqldump -u root -pSecretPass blog> /home/jatin/sql/blog.sql

Restoring the mysql tables from the mydqldump output files :

Restoring the database from the dump file is even easier. just use the following syntax :
   1.
      mysql -u root -p[root_password] [database_name] <  dumpfilename.sql




COPY One file:

rsync -v sourcefile destination


For Syncing the files

rsync -avz source destination


No comments:

Post a Comment