Last update at :2024-07-08,Edit by888u
1. Introduction to PyBackup:
Can back up local sites and databases (mysql, mssql), and remote FTP sites and remote databases (mysql, mssql),
Synchronize backup files to Ftp, Alibaba Cloud Oss, Tencent Cloud Cos, OneDrive, Email, and local, and delete old backup files for a specified number of days
2. PyBackup installation
1. One-click Linux configuration environment
wget --no-check-certificate https://raw.githubusercontent.com/LoneKingCode/PyBackup/master/PyBackup/backup/plugin/init.sh -O pybackup.sh && bash pybackup.sh After executing this program, store it in the same directory as the script. After installation, enter python3 -h, pip3 -h and 7za to check the results and determine whether the installation is successful. Then set up your own scheduled tasks using crontab or the built-in plan in the panel. This program directory/plugin/cron.sh is used to set scheduled tasks using crontab. Modify the path inside and execute sh cron.sh. The command set by backup.py as the main program is python3 yourPath/backup.py2. Installation under Windows
First download and install python3.6.3 https://www.python.org/ftp/python/3.6.3/python-3.6.3.exe After installation, enter the python3 -h and pip3 -h commands in the command prompt to see the results and determine whether the installation is successful. Then download this program and unzip it https://github.com/LoneKingCode/PyBackup/releases Then modify this line of command in the /backup/plugin/init.bat batch file in the program directory schtasks /create /tn "backup_web_db" /ru system /tr "python3 /yourPath/backup.py" /sc DAILY /st 01:00 Modify backup_web_db as the scheduled task name, modify yourPath as the actual location of the file, DATLY as daily, and execute at 01:00 a.m. If you want to plan to add scheduled tasks to Baidu schtasks or windows for other cycles After the modification is completed and saved, double-click init.bat to run it. The function of init.bat is to install python3 dependent libraries and set up scheduled tasks.3. How to use
Let me tell you in advance:
[] in the configuration file is an array, and the internal elements are separated by, {'key':'value','key':'value'} is a dictionary All [{}] structures can be set to multiple configurations [{},{},{},]Modify the configuration in config.py
#Backup site directory #type: local, ftp local (local), ftp (remote site backup) #path: The directory to be backed up. Remember to use double slashes \\ under Windows. Just use / under Linux. For example, /home/wwwroot/myweb #archive_type: 7z,zip,tar (types supported by 7zip) #archive_password: Compressed package password Additional configuration is required when #type is ftp: host: FTP server address port: port username: username password: password SITES = [{ 'type':'local','path':'D:\\wwwroot\\www.aa.com', 'archive_type':'zip','archive_password':'123' }, { 'type':'ftp', 'path':'/WEB', 'archive_type':'zip','archive_password':'123', 'host':'yourFtpUrl','port':21,'username':'yourFtpUsername','password':'yourFtpPwd'}] #Backup database #type: database type mssql,mysql #database_name: database name #username: database username #password: database password #host: database server address. If empty, it means local #archive_type: 7z,zip,tar (types supported by 7zip) #archive_password: Compressed package password #sqlcmd_path or mysqldump_path: mssql and mysql command line tool paths. No need to modify under windows. Please set to '' for linux. #***Notice*** #When setting up the backup remote database, please set it in the database so that the backup machine IP can be connected or any IP can be connected (mysql adds a user and sets the Host to % or specify the IP) #mysql #linux If the mysqldump command can be executed directly, set mysqldump_path to '', otherwise set it to the actual path. Set the location of mysqldump.exe under windows. The plugin directory of this program comes with (MYSQL5.7) #mssql(Sql Server) #linux If the SQLCMD command can be executed directly, set sqlcmd_path to '', and set the location of SQLCMD.exe under windows. The plugin directory of this program comes with (SQLSERVER2014) # If necessary, you can replace the command line tool with the version you need in the plugin directory. DATABASES = [{'type':'mssql','database_name':'yourDatabaseName','username':'sa','password':'123','host':'123.123.123.123', 'archive_type':'zip','archive_password':'123','sqlcmd_path':os.path.join(str(ROOT_DIR),'plugin') + '\\SQLCMD.exe'}, {'type':'mysql','database_name':'yourDatabaseName','username':'test','password':'asd','host':'aa.aa.com', 'archive_type':'zip','archive_password':'123','mysqldump_path': os.path.join(str(ROOT_DIR),'plugin') + '\\mysqldump.exe'}] #Keep files within a few days KEEP_DAYS = 7 #Local backup file storage location LOCAL_SAVE_PATH = {'sites':'D:\\Save\\backup\\sites','databases':'D:\\Save\\backup\\databases'} #Temporary storage location of backup files TEMP_SAVE_PATH = 'D:\\Save\\backuptemp' #Remote backup type If empty, it will only be saved locally. #Optional ftp, email, oss, cos, onedrive #***Notice*** #email, please pay attention to the size of the attachment. Some limits are 25MB and some are 50MB. REMOTE_SAVE_TYPE = ['oss','cos','ftp','onedrive'] #FTP backup configuration #host: FTP server address #port: FTP port #username: FTP username #password: FTP password #site_save_path: The path where the site backup file is saved. Make sure the path already exists. #db_save_path: The path where the database backup file is saved. Make sure the path already exists. FTP_OPTIONS = [{'host':'yourFtpUrl','port':21,'username':'yourFtpUsername','password':'yourPwd', 'site_save_path':'/backup/sites','db_save_path':'/backup/databases'},] #Alibaba Cloud OSS configuration #sitedir: directory where site backup files are saved #databasedir: Database file storage directory #url:your oss address #bucket: bucket name #accesskeyid: AccessKeyId #accesskeysecret : AccessKeySecret OSS_OPTIONS = [{'sitedir':'sites','databasedir':'databases','url':'oss-xx-xxxx.aliyuncs.com','bucket':'bucketName', 'accesskeyid':'ASDI123ISDD12','accesskeysecret':'SAD123ASD123ASD213ASD'},] #Tencent cloud COS configuration #sitedir: directory where site backup files are saved #databasedir: Database file storage directory #region:region #bucket: bucket name #accesskeyid: AccessKeyId #accesskeysecret : AccessKeySecret COS_OPTIONS = [{'sitedir':'sites','databasedir':'databases','region':'ap-hongkong','bucket':'bucketName', 'accesskeyid':'ASD123ASDASD123','accesskeysecret':'ASD123ASDASD123ASD'},] #OneDriveConfiguration #name: name #Used to distinguish the configuration in the configuration file, it can be set to multiple {'name':'backup1' .....}, {'name':'backup2' .....}, which requires you to authenticate more different accounts #sitedir: directory where site backup files are saved #databasedir: Database file storage directory ONE_DRIVE_OPTION = [{'name':'backup1','sitedir':'sites','databasedir':'databases',}] #The default does not need to be modified. It is used to apply for API access. This is provided by MoeClub. ONE_DRIVE_CLIENT = {'client_id':'ea2b36f6-b8ad-40be-bc0f-e5e4a4a7d4fa','client_secret':'h27zG8pr8BNsLU0JbBh5AOznNS5Of5Y540l/koc7048='} #Email backup configuration #Send configuration #host: Email smtp server address #username: username password: password port: port is_ssl: whether to encrypt the SSL connection True or False EMAIL_OPTIONS_SENDERS = [{'host':'smtp.AA.com','username':'AA@AA.com','password':'123446','port':465,'is_ssl':True},] #Receive email EMAIL_OPTIONS_RECEIVERS = ['receivebackup@foxmail.com',] #7z.exe location Use 7zip to compress #Only required for windows (already included in the program plugin directory) #linux Just install "p7zip" WINDOWS_7ZIP_PATH = os.path.join(str(ROOT_DIR),'plugin') + '\\7z.exe'Project address: https://github.com/LoneKingCode/PyBackup
Local download: PyBackup-201902
Recommended site searches: host server rental, host rental, network registration, cheap domain name IP proxy address, US vps host, free proxy IP, best US server, mobile proxy IP, app server rental,
发表评论