Add copying between domains
cowsun opened this issue · 3 comments
Love the script, is exactly what I was looking for. Great work.
That said, I think it would be fantastic to extend the functionality of ./domain.sh add | rem to include copy (cpy in example) though easier said than done I'm sure!
Example:
setup main wp site
./domain.sh add user1 user1.com
./wordpress.sh
setup a test wp site
./domain.sh add user1 test.user1.com
./wordpress.sh
copy mainsite to test site
./domain.sh cpy user1 user1.com user1 test.user1.com
user1.com remains the same,
test.user1.com databases & home/user1/domains/test.user1.com folder etc are overwritten with user1.com databases & home/user1/domains/user1.com etc.
make some updates, test some stuff, show some clients some stuff on test.user1.com, then copy back to user1.com.
Copying the domain files should be pretty straight forward using "cp". But, I'm not sure how this can be done for the databases since the script needs a record of the owners for the respective databases.
If you intend to overwrite the main site with the test site, its probably easier to delete the main site, re-add it, and simply copy the files over. E.g.
./domain.sh rem user1 user1.com
./domain.sh add user1 user1.com
cp -rf /home/user1/domains/test.user1.com/public_html/ /home/user1/domains/user1.com/public_html/
These commands look like they might nearly cover the mysql side of things?
"The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch.
If you want to back up a single database, you merely create the dump and send the output into a file, like so:
mysqldump database_name > database_name.sql
Multiple databases can be backed up at the same time:
mysqldump --databases database_one database_two > two_databases.sql
It is also simple to back up all of the databases on a server:
mysqldump --all-databases > all_databases.sql
Restoring a Backup
Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.
mysql database_name < database_name.sql
If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:
mysql --one-database database_name < all_databases.sql"
Ripped this this from here: http://www.liquidweb.com/kb/how-to-back-up-mysql-databases-from-the-command-line/
@cowsun -1 servers already has the basic tools to quickly perform such operations. Why complicate things? In addition, some CMS scripts eg. Joomla! will not work after the operation because you need too edit configuration file anyway to meet correct folders paths and database access. Honestly I'd be afraid to make such operations by using a script on a production server.