I am looking to start using git to version some magento 2 sites that we have created, but we also want need to version the database because we dont want to overwrite the sales/customer or any other data that we want to keep on the production side.
so my 1st question is what files/directories should i put in the .gitignore and exclude from putting in the repository.
secondly how do we go about the database as we cant just take a dump of the dev database and import on the staging or production server?
Hope this makes sense
Thanks in advanced
Regarding your two questions:
1- Here you an find the .gitignore file for Magento 2:
/.buildpath /.cache /.metadata /.project /.settings atlassian* /nbproject /sitemap /.idea /.gitattributes /app/code/Magento /app/design/*/Magento /app/etc /app/i18n/magento /app/*.* /bin /dev/shell /dev/tests/*/framework /dev/tests/*/testsuite/Magento /dev/tests/*/tmp /dev/tests/*/etc /dev/tests/*/*.* /dev/tests/*.* /dev/tests/api-functional/config /dev/tests/api-functional/_files/Magento /dev/tests/js/JsTestDriver/framework /dev/tests/js/JsTestDriver/testsuite/lib /dev/tests/js/JsTestDriver/testsuite/mage /dev/tests/js/JsTestDriver/*.* /dev/tests/js/jasmine/assets /dev/tests/js/jasmine/spec_runner /dev/tests/js/jasmine/tests/app/code/Magento /dev/tests/js/jasmine/tests/lib/mage /dev/tests/js/jasmine/*.* /dev/tests/performance /dev/tests/functional/lib/Magento /dev/tests/functional/tests/app/Magento /dev/tests/functional/testsuites/Magento /dev/tests/functional/utils /dev/tools/Magento /dev/tools/grunt /dev/tools/*.* /dev/*.* /lib /pub /setup /var /vendor /*.* !/composer.json !/composer.lock !/README.md
2- Backing up a database on a regular basis is really simple. The only thing you have to do is creating a shell script that runs the following commands on your development server:
mysqldump -u<username> -p<password> <database-name>
In addition to that example, you have to add the shell commands to move the database dump to the remote staging/produciton server. Finally, you should create a cron job to run the script on a regular basis.