通过使用cron
job,我成功地在 Ubuntu 上创建了 mysql 数据库的备份。下面是下面的命令mysqldump.sh
/opt/lampp/bin/./mysqldump -u root database-name | gzip >/db-backup/"mysql_db-$(date +"%Y-%m-%d %T").sql.gz"
我正在使用作业运行上面是作业cron
的命令cron
* * * * * /db-backup/mysqldump.sh
我的问题是,我不想将 sql 备份文件创建到同一个 ubuntu (IP: 192.168.2.10)。实际上,我需要将 sql 备份文件复制到同一网络中的另一个 ubuntu (IP: 192.168.2.11)
我尝试将cron
作业命令更改为,* * * * * /192.168.2.11/db-backup/mysqldump.sh
但 sql 备份文件未复制到192.168.2.11/db-backup/
任何帮助都将非常感激。
答案1
你可以使用将备份文件发送到另一个 Ubuntu rsync
,或者scp
你可以删除系统上的备份
使用此链接用于学习rsync
RSync 有用的选项:
-r --> Recursive
-b --> Backup
-u --> Update (--inplace, --append)
-d --> Transfering dirs without recursive
-l --> Copy symbolics as symbolics
-p --> Preserve permissions
-E --> Preserve Executability
-o --> Preserve OwenrShip
-g --> Preserve Groups
-t --> Preserve modifition time
-z --> Compress
-v --> Increase verbosity
-a --> Archive mode
-H --> Preserve hard links
-e --> To run shell command on the remote server
-e <protocol> --> Over that protocol (e.g. ssh)
-h --> Human readable
-P --> Show the progress during the progress (SMILE), Same as --progress
--safe-link --> Ignore symbolic links that point out of the tree
--existing --> Ignore creating new files
--ignore-existing --> Ignore updating existing files
--remove-source-files --> Sender remove synced files
--progress --> Show the progress during the progress (SMILE)
--log-file=FILE --> Sending logs will be stored to FILE
--include=PATTERN --> Sync files that have PATTERN filter in themselves
--exclude=PATTERN --> Don't sync files that have PATTERN filter in themselves
--max-size='SomeK' --> Only send or recieve files less than SomeK
以下列举一些例子:
rsync -t [Pattern (e.g. *.c)] [PurposeMachine]:Path
Send all file with that pattern in the current dir to purpose machine in the path (if exist only send differences)
e.g. rsync -t *.c foo:/src
rsync -avz [Machine]:Path/dir PathHere :
Download all files recursivly that are in the dir directory to the PathHere/dir
File transfering is archive mode that means Symbolic links, devices, attributes, permissons, ownerships, etc are preseved
e.g. rsync -avz foo:src/bar /data/tmp
rsync -avz [Machine]:Path/dir/ PathHere :
Download all files recursivly that are in the dir directory to the PathHere/
File transfering is archive mode that means Symbolic links, devices, attributes, permissons, ownerships, etc are preseved
e.g. rsync -avz foo:src/bar/ /data/tmp
rsync -av NowHere/dir[/] /Dest :
rsync -av [host]:: /Dest: [OR rsync -av [host]::moudle /Dest]
All files in remote dir will be transfered