Cloning website, making staging copy (v-clone-website)

User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

We have an script for website cloning: v-clone-website

Let's say you have yourdomain.com and you want to make stage.yourdomain.com in one command.
In your SSH run:

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website yourdomain.com stage.yourdomain.com
(first parameter is SOURCE website, second parameter is DESTINATION website)

Our script will show you what will be copied, what database will be created, what URL will be replaced, just press enter to confirm it.
And that's all, the script will clone your site.
WordPress, Joomla and Open-Cart will be detected automatically, no need to enter DB credentials manually.



Want to copy stage back to production?
In your SSH run:

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website stage.yourdomain.com yourdomain.com
Script will do the rest.

By default, destination database will be: myuser_domain_com (or, in case it's subdomain, then it will be myuser_subdomain_domain_com )





Optional:
If you want to specify destination database, you can add parameter: --DATABASE_SUFIX=_name_of_new_site or --TO_DATABASE=myuser_exactdbname

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website yourdomain.com stage1.yourdomain.com --DATABASE_SUFIX=_stage1
or

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website stage1.yourdomain.com yourdomain.com --TO_DATABASE=myuser_wp




For custom CMS

In case that you want to clone custom CMS which doesn't store files outside of /public_html folder and there is only one config file, run:

Code: Select all

/usr/local/vesta/bin/v-clone-website domain1.com domain2.com --CMS_TYPE='other' --CONFIG_FILE='config.php' --FROM_DATABASE_NAME='myuser_db' --FROM_DATABASE_USERNAME='myuser_db' --FROM_DATABASE_PASSWORD='mysqlpass1234'
Another scenario would be if you want to clone CMS which does store files outside of /public_html folder and have multiple config files, then you will run this command:

Code: Select all

/usr/local/vesta/bin/v-clone-website domain1.com domain2.com --CMS_TYPE='other' --SITE_SUBFOLDER='..' --SEARCH_FOR_CONFIGS_DATABASE_NAME=1 --CONFIG_FILE='public_html/config.php' --FROM_DATABASE_NAME='myuser_db' --FROM_DATABASE_USERNAME='myuser_db' --FROM_DATABASE_PASSWORD='mysqlpass1234'
Commands explanation:

--CMS_TYPE='other' If CMS is different from WordPress, Joomla or Open-Cart
--SITE_SUBFOLDER='..' If there are files outside of /public_html folder, use this command to navigate up one directory level. Or you can use this command to navigate directly to subfolder where all files are stored
--CONFIG_FILE='config.php' If there are files outside of /public_html folder, you have to set path to config file, '/public_html/config.php'
--SEARCH_FOR_CONFIGS_DATABASE_NAME=1 Used in case that CMS has multiple config files

Keep in mind that you have to manually read database name/username/password from config file and insert those information in script.

See source code of the script for all available parameters: v-clone-website

Tags:
wpinsites
Posts: 14
Joined: Thu Jul 30, 2020 7:06 am

Thanks for this excellent tool!

I have just used it for the first time to create a staged site to test updates, and now want to copy the staged site back to the production site. I noted, however, that when it displayed the summary of the information to be used to complete the clone, the DATABASE_SUFFIX was set to _migrated, as it was when creating the clone. Is this correct? Should I be using an override so that it doesn't change the structure of the database on the original site?
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

Code: Select all

--DATABASE_SUFIX=... (default is '_migrated')
so you can override it with this parameter.
If you are cloning site to different account, then you can set it to empty string:

Code: Select all

--DATABASE_SUFIX=""
wpinsites
Posts: 14
Joined: Thu Jul 30, 2020 7:06 am

So if I'm copying the cloned (staged) site back to the original, should I override this parameter and set it blank so that I don't end up with the "_migrated" suffix on the original site?
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

wpinsites wrote: Thu Jul 29, 2021 12:36 am So if I'm copying the cloned (staged) site back to the original, should I override this parameter and set it blank so that I don't end up with the "_migrated" suffix on the original site?
If you clone stage back to original, this script will figure out that it's stage (thanks to '_migrated' sufix) and will copy database directly to original database.

So, let's say we have database test_wp on test.com domain.

If you clone it first time:
v-clone-website test.com stage.test.com
you will get database test_wp_migrated

but...
if you want to copy the stage back to the original:
v-clone-website stage.test.com test.com
then test_wp_migrated will be copied back to test_wp

So, thanks to '_migrated' sufix, script will figure out that you want to copy stage back to original.
wpinsites
Posts: 14
Joined: Thu Jul 30, 2020 7:06 am

Brilliant. You're awesome! Thanks! :D

I love this script. It is so quick. :!:

Any plans to add this (and possibly the script to install WordPress) to the web interface, possibly in the domain options menu when you hover a domain? :idea:
kamerbk
Posts: 1
Joined: Fri Jun 24, 2022 7:26 am

Hello,

when i want to clone my website;

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website mywebsite.com stage.mywebsite.com
I am getting error like this, what could be the cause of the error? I am using wordpress

Code: Select all

/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 127: get_database_name_without_user_prefix: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 130: get_database_name_without_user_prefix: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 133: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 136: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 139: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 142: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 145: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 148: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 151: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 154: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 157: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 160: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 163: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 166: escape_shell_quote: command not found
Error: FROM_CONFIG_FILE_FULL_PATH  does not exists
Last edited by kamerbk on Fri Jun 24, 2022 7:34 am, edited 1 time in total.
smartis
Posts: 2
Joined: Mon Oct 30, 2023 2:06 pm

Hello, is there a command that can create sites in bulk? I want to create 1 main site and copy it to 50 different domains.
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

kamerbk wrote: Fri Jun 24, 2022 7:31 am Hello,

when i want to clone my website;

Code: Select all

sudo /usr/local/vesta/bin/v-clone-website mywebsite.com stage.mywebsite.com
I am getting error like this, what could be the cause of the error? I am using wordpress

Code: Select all

/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 127: get_database_name_without_user_prefix: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 130: get_database_name_without_user_prefix: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 133: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 136: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 139: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 142: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 145: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 148: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 151: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 154: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 157: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 160: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 163: escape_shell_quote: command not found
/usr/local/vesta/bin/v-get-database-credentials-of-domain: line 166: escape_shell_quote: command not found
Error: FROM_CONFIG_FILE_FULL_PATH  does not exists
See viewtopic.php?f=17&t=49
User avatar
myVesta
Site Admin
Posts: 928
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 times
Been thanked: 6 times

smartis wrote: Mon Oct 30, 2023 2:08 pm Hello, is there a command that can create sites in bulk? I want to create 1 main site and copy it to 50 different domains.
Copy/paste command 50 times with 50 different domains.
Post Reply