0

By using cron job I've successfully created a backup of mysql database on the Ubuntu. Below is the command under mysqldump.sh

/opt/lampp/bin/./mysqldump -u root database-name | gzip >/db-backup/"mysql_db-$(date +"%Y-%m-%d %T").sql.gz"

I'm running above using cron job below is the command of cron job

* * * * * /db-backup/mysqldump.sh

My question is, I don't want to create the sql backup file to the same ubuntu (IP: 192.168.2.10). Actually I need to copy the sql backup file to another ubuntu (IP: 192.168.2.11) which is in same network

I tried to change cron job command to * * * * * /192.168.2.11/db-backup/mysqldump.sh but sql backup file is not copying to 192.168.2.11/db-backup/

Any help will be highly appreciable.

1 Answer 1

2

You can send the backup file to the other Ubuntu using rsync or scp then you can delete the backup on your system or not

Use this link for learning rsync

RSync useful options:

    -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

And some examples:

    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  
11
  • sql backup file is not a single file it is creating with current date and time so every time I have a sql backup file is creating with the new name like "mysql_bk_2010-08-02 10:40" and so on...
    – shaji
    Aug 2, 2015 at 7:49
  • @shaji So what's the problem? You can use rsync on a directory and rsync won't send duplicates Aug 2, 2015 at 7:53
  • I submit command from 192.168.2.10 > rsync db_backup/ 192.168.2.11/db_backup Now this error is appearing skipping directory . rsync: change_dir#3 "/192.168.2.11" failed: No such file or directory (2) rsync error: errors selecting input/output files, dirs (code 3) at main.c(712) [Receiver=3.1.0] Please help on the above issue
    – shaji
    Aug 2, 2015 at 8:23
  • I submitted another command "rsync -a ~/db_backup/ [email protected]:db_backup" but this error appeared ssh: connect to host 192.168.2.11 port 22: Connection refused rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]
    – shaji
    Aug 2, 2015 at 8:47
  • You must install ssh on your remote computer. To do so: apt-get install openssh-server Aug 2, 2015 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .