作者归档:xinlu

数据库备份与恢复

一、备份脚本

#!/usr/bin/bash
path_current=$(cd "$(dirname "$0")"; pwd)
name_current=$(basename "$0" .sh)
echo $path_current
echo $name_current

if [ ! -d $path_current/backup/ ];then
   echo "create backup path: $path_current/backup"
   mkdir -p $path_current/backup
fi

path_backup=$path_current/backup/
echo "backup path: ${path_backup}"

dball=(commams-bigdata commams-bos commams-coupon commams-device commams-face commams-goods commams-log commams-logistics commams-marketing commams-member commams-oa commams-oauth commams-order commams-partner commams-pay commams-payaccount commams-peripherals commams-sms commams-wallet commams-wms)
for db in ${dball[@]};do
   if [ ! -f ${path_backup}/"$db".sql ];then
      echo "backup next database:$db"
      mysqldump --host xxxxx --port 196227  -u abc -p'yyy3' --set-gtid-purged=off --databases "$db" > ${path_backup}/"$db".sql
      if [ $? -ne 0 ]; then
         rm -f ${path_backup}/"$db".sql
         echo "failed to backup the database."
         exit 1
      fi
   fi
done
echo "success to backup database from production"

二、restore.sh恢复脚本

#!/usr/bin/bash
path_current=$(cd "$(dirname "$0")"; pwd)
name_current=$(basename "$0" .sh)
echo $path_current
echo $name_current

if [ ! -d $path_current/backup/ ];then
   echo "should first backup database."
   exit 1
fi

path_backup=$path_current/backup/
echo "backup path: ${path_backup}"

dball=(commams-bigdata commams-bos commams-coupon commams-device commams-face commams-goods commams-log commams-logistics commams-marketing commams-member commams-oa commams-oauth commams-order commams-partner commams-pay commams-payaccount commams-peripherals commams-sms commams-wallet commams-wms)

for db in ${dball[@]};do 
   if [ -f ${path_backup}/"$db".sql ];then
      echo "restore database:$db"
      mysql --host sxxxxx --port 3307  -uroot -p'123456' < ${path_backup}/"$db".sql && echo "$db is ok"
   fi
done
echo "success to restore database from production"

xdebug3的调试开启方式

xdebug2和xdebug3的开启调试方式是不同的。

此外xdebug3的默认端口改为9003了,故需要修改PHPSTORM的调试端口。
——xdebug3—–的开启方式。
zend_extension=”xdebug-3.0.1.so”
xdebug.mode=debug

—-以下是xdebug2的开启方式———-
zend_extension=”xdebug-2.7.2.so”
xdebug.remote_enable = On
xdebug.profiler_enable = On
xdebug.profiler_enable_trigger = On

xdebug.auto_trace = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.trace_output_dir = “/data/logs/xdebug”
xdebug.profiler_output_dir = “/data/logs/xdebug”
xdebug.dump.GET = *
xdebug.dump.POST = *
xdebug.dump.COOKIE = *
xdebug.dump.SESSION = *
xdebug.var_display_max_data = 9056
xdebug.var_display_max_depth = 50

REMI安装PHP插件不同版本

https://centos.pkgs.org/7/remi-x86_64/

FROM centos:7.8.2003
RUN yum install -y wget && \
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
rpm -Uvh epel-release-latest-7.noarch.rpm && rm -f epel-release-latest-7.noarch.rpm && \
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
rpm -Uvh remi-release-7.rpm && rm -f remi-release-7.rpm && \
yum install -y yum-utils && \
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo && \
yum install -y crontabs && \
yum install -y openresty && \
yum install -y supervisor && \
yum install -y php72 &&\
yum install -y php72-php-pecl-psr php72-php-pear php72-php-pecl-amqp php72-php-bcmath php72-php-bcmath php72-php-mysqlnd php72-php-pgsql php72-php-common php72-php-gd php72-php-mbstring php72-php-pdo php72-php-xml php72-php-xmlrpc php72-php-soap php72-php-opcache php72-php-process php72-php-sodium && \
yum install -y php72-php-pecl-zip php72-php-pecl-redis php72-php-pecl-mongodb php72-php-pecl-grpc php72-php-pecl-protobuf php72-php-pecl-uuid &&\
yum install -y php72-php-fpm && \
ln -sf /usr/bin/php72 /usr/bin/php && \
ln -sf /opt/remi/php72/root/usr/sbin/php-fpm /usr/bin/php-fpm && \
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/bin/nginx && \
mkdir -p /data/www/html && mkdir -p /data/logs \
php --version && \
php --modules
COPY ./nginx/ /usr/local/openresty/nginx/conf/
COPY ./start.sh /start.sh
RUN chmod a+x /start.sh
COPY ./supervisor.ini /etc/supervisord.d/
COPY ./php-fpm/ /etc/opt/remi/php72/
COPY ./html/ /data/www/html/
COPY ./logrotate/ /data/logrotate/
WORKDIR /data/www
EXPOSE 80
ENTRYPOINT ["/bin/bash", "/start.sh"]

https://centos.pkgs.org/7/remi-x86_64/php72-php-pecl-grpc-1.33.1-1.el7.remi.x86_64.rpm.html

yum install php72-php-pecl-grpc-1.33.1

GIT误删库如何恢复

转:
误操作删除服务器上git仓库的处理方法

说明:

git 服务器上仓库代码不小心被删除了,但是通过git clone下来的code存在

另外git 服务器上没有建立任何branch信息;

1.在之前clone过服务器代码的客户端机器上,找到clone下来的代码目录,

执行git remote -vv
查询原来git 仓库所在服务器的IP地址以及路径;

2.根据步骤1上查询的结果,在服务器上找到对应路径,创建git仓库;

git init –bare

3.在客户端之前clone 代码所在目录,强制push客户端的代码至服务器

git push origin master –force

这样原来clone下来的代码以及change log等信息,就会被强制clone到服务器上;

说明:此处必须加–force选项,否则会因服务器上仓库信息与客户端仓库信息不匹配导致push失败
——————————————————
免密模式中的.ssh目录必须是700权限,和authorized_keys必须是600权限

控制台应用静态库编译

cmake_minimum_required(VERSION 3.14)
project(CommaSdkActivator)

set(CMAKE_CXX_STANDARD 11)


# yum install glibc-static libstdc++-static
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")

if(WIN32)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS,5.01")
endif()

if(MSVC)
    # Use the static C library for all build types
    foreach(var
        CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
        CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
      )
      if(${var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
      endif()
    endforeach()
endif(MSVC)

add_executable(CommaSdkActivator main.cpp)

指定ndk的库输出

defaultConfig {
applicationId “com.commaai.facesdkdemo”
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName “1.0”

testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner”

ndk {
abiFilters “armeabi-v7a”
}
}

Android线程异步处理

private ExecutorService executorService;
private Future mFutureBitmapRunnable;

第一步:
this.executorService = Executors.newSingleThreadExecutor();
第二步:
on camera thread callback,do like below.
public void takePhoto(ImiDevice.ImiFrame frame) {
            if (mFutureBitmapRunnable != null && !mFutureBitmapRunnable.isDone()) {
                return;
            }
            ByteBuffer buf = frame.getData();
            buf.position(0);
            final byte[] rgb24 = new byte[buf.remaining()];
            buf.get(rgb24);
            final int width = frame.getWidth();
            final int height = frame.getHeight();
            mFutureBitmapRunnable = executorService.submit(new Runnable() {
                @Override
                public void run() {
                    //to do
                }
           });
}

VT102图形测试whiptail

#!/bin/bash

whiptail --title "K8s,  Vision @ 2019" --menu "Choose your option" 20 65 13 \
"1" "Single K8s One-click" \
"2" "Cluste K8s One-click" \
"3" "Cluste K8s add node" \
"4" "Single K8s add node" \
"5" "del node" \
"6" "Uninstall K8s" \
"7" "Quit"  3>&1 1>&2 2>&3
#!/bin/bash
whiptail --title "导入集群IP地址(包含本机ip默认第一个ip对应本机ip作为master)" --yes-button "YES" --no-button "NO"  --yesno "批量导入集群IP地址?" 10 60
#!/bin/bash
whiptail --title "#请输入本机Ip(master)并回车#" --inputbox "请检查IP是否一致,确定提交?" 10 60 "$IP" 3>&1 1>&2 2>&3
#!/bin/bash
#---
if ( whiptail --title "Title hylan:yesno" --yesno "Choose between Yes and No." 10 60 ) then
     echo "You chose Yes. Exit status was $?."
else
     echo "You chose No. Exit status was $?."
fi
#---
if (whiptail --title "Title hylan:yesno" --yes-button "Hylan" --no-button "Candy"  --yesno "Which do you like better?" 10 60) then  
   echo "You chose Hylan. Exit status was $?."; 
   echo "You Best!"
else    
   echo "You chose Candy. Exit status was $?.";
fi
#---
whiptail --title "Title hylan:msgbox" --msgbox "Create a message box with whiptail. Choose Ok to continue." 10 60
#---
whiptail --title "Title hylan:inputbox" --inputbox "What is your pet's name?" 10 60 hylancandy 3>&1 1>&2 2>&3
#---
whiptail --title "Title hylan:passwordbox" --passwordbox "Enter your password and choose Ok to continue." 10 60 3>&1 1>&2 2>&3
#---
whiptail --title "Title hylan:menu" --menu "Choose your option" 15 60 4 \
"1" "Grilled Spicy Sausage" \
"2" "Grilled Halloumi Cheese" \
"3" "Charcoaled Chicken Wings" \
"4" "Fried Aubergine"  3>&1 1>&2 2>&3

#---
whiptail --title "Title hylan:checklist" --checklist "Choose preferred Linux distros" 15 60 4 "debian" "Venerable Debian" ON "ubuntu" "Popular Ubuntu" OFF "centos" "Stable CentOS" ON "mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3

{
     for (( i=0 ; i<=100 ; i+=20 )); do
         sleep 1
         echo $i
     done
} | whiptail --gauge "Please wait while installing" 6 60 0

#---
whiptail --title "Title hylan:checklist" --radiolist "Choose preferred Linux distros" 15 60 4 "debian" "Venerable Debian" ON "ubuntu" "Popular Ubuntu" OFF "centos" "Stable CentOS" ON "mint" "Rising Star Mint" OFF 3>&1 1>&2 2>&3