Let’s say you have websites in /var/www
folder that you want to transfer. Compressing them first will save bandwidth as well as transfer time.
1# tar czf <filename> <source>
2tar czf aamnah.tar.gz /var/www/aamnah.com
c
- create
z
- compress (gzip)
f
- take a filename
v
- verbose (optional, if you wanna see lines fly by on the termianl)
SCP (Secure Copy) to the rescue
1scp -P 1234 -i ~/.ssh/blah file1.tar.gz file2.tar.gz file3 file4.sql.gz user@server.domain.com:/location-on-new-server
-P
for the target server-i
, saves you the password prompt. Key must already be authenticated with target server.1# mysqldump -u <uname> -p<pass> <dbname> | gzip -9 > <backupfile.sql.gz>
2mysqldump -u username -p --all-databases | gzip -9 > allDatabases.sql.gz
--all-databases
will backup ALL databases, including mysql
, use
, db
, tables_priv
, and columns_priv
etc. These tables include user accounts and global privilieges etc.
To restore compressed backups
1# gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]
2gunzip allDatabases.sql.gz
3mysql -u username -p < allDatabases.sql
For the above to work, the databases need to exits or the backup script needs to have the CREATE DATABASE
queries for the databases.
If you’re importing into existing databases, use the mysqlimport
command
1mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]