- put a .my.cnf file into your home directory, for example
$ cat ~/.my.cnf
[client]
user=yourDbUserName
password=yourDbPassword
host=yourDbHost
- write a bash script to update the database
#!/bin/bash
set -ex
variable=`TZ="Africa/Abidjan" date '+%Y-%m-%d %H:%M:%S'`
sql="Your SQL statement with ${variable}"
logDir=/data/Logs/`date '+%Y'`/`date '+%m'`
mkdir -p "${logDir}"
echo "${sql}" >> "${logDir}/`date '+%d'`.sql"
mysql -v -v -e "${sql}" >> "${logDir}/`date '+%d'`.result.txt"
- put a line by run crontab -e
the end.
严格来说,二者是两个维度,并没有必然的固定的映射关系。只是通常情况下,约定俗成的:
--mode test <=> NODE_ENV=test
--mode development <=> NODE_ENV=development
--mode production <=> NODE_ENV=production
--mode staging <=> NODE_ENV=staging
那怎么知道手头的项目是否符合这个约定俗成呢?通常来说,你可以看一下项目根目录下的 .env 系列文件,一般情况下,NODE_ENV 变量会定义在那里。
To be honest, 5 minutes is not enough, especially for the first time you do it.
What you need to prepare
- a VPS (Virtual Personal Server) with public IP
- an Nginx Server running on that VPS.
- an OpenVPN Server running on that VPS. (or you have tailscale service running on both your local machine & the VPS server)
- a domain name
- the CertBot tool from Let's Encrypt
Steps to get it to work
For example,
- your local dev environment is running on
10.8.0.2:8080
- your domain name is
dev.myawesomedomain.com
- create a new virtual server on your Nginx server, you can use the config below as a template.
upstream local-front-end-env {
server 10.8.0.2:8080;
}
server {
listen 80;
listen [::]:80;
server_name dev.myawesomedomain.com;
access_log /var/log/nginx/dev.myawesomedomain.com.access.log;
error_log /var/log/nginx/dev.myawesomedomain.com.error.log;
location / {
proxy_pass http://local-fornt-end-env;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# the following lines is used to support wss:// protocol
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
large_client_header_buffers 4 32k;
}
- run
sudo certbot --nginx
to automatically config your new-added virtual server.
- run
sudo nginx -s reload
& test it in browser
- You need to modify your package.json to listen your vpn IP
- "serve": "vue-cli-service serve",
+ "serve": "vue-cli-service serve --host=0.0.0.0 --port=8080 --public=https://dev.myawesomedomain.com",
- You may need to modify your
vue.config.js
to fix the "Invalid Host header" error when visiting your site by https instead of localhost:8080
.
--- a/vue.config.js
+++ b/vue.config.js
@@ -1,6 +1,9 @@
module.exports = {
configureWebpack: {
externals: {
+ },
+ devServer: {
+ disableHostCheck: true
}
},
That's it.
- Bound object changes but the UI didn't change. Solution:
Template part,
<el-select v-model="form.categoryIdList" multiple @change="setValue(form.categoryIdList)">
Component part,
setValue(object) {
this.$set(this.form, this.form.categoryIdList, object)
},
- VUE_APP_CUSTOM_VARIBLE doesn't work, solution:
Restart your dev server.
- on a server with huge disk space, run
crontab -e
and put the following code in it (you may need to change the directory names to fit your situation)
30 3 * * * mysqldump --databases DB1 DB2 DB3 DB4 | gzip > /data/backups/mysql/db_`date '+\%Y\%m\%d-\%H\%M\%S'`.sql.gz
30 4 * * * find /data/backups/mysql/db_* -mtime -1 -exec scp {} anotherserver:/data/backups/mysql \;
30 5 * * * find /data/backups/mysql/db_* -mtime +30 -exec rm {} \;
- on another server, run
crontab -e
and put the following line into it:
30 5 * * * find /data/backups/mysql/db_* -mtime +7 -exec rm {} \;
summary & explanation:
- at 3:30 backup MySQL data in a local directory and keep latest 30 days backup in that directory
- at 4:30 transfer the latest backup to another server in case the first backup may be destroyed by an accident.
- at 5:30 remove the oldest backup on the local backup server (the code shows that the latest 30 days backups are kept on the server).
- at 5:30 remove the oldest backup on the remote server (the code shows that only the latest 7 days backups are kept on that server).