ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Doubt on a script- Backup site & DB

    IT Discussion
    scripting linux rsync
    3
    22
    3.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      DustinB3403
      last edited by

      But with the wildcard, you can't delete files. (Just read that in the manual)

      1 Reply Last reply Reply Quote 0
      • S
        scottalanmiller @DustinB3403
        last edited by

        @DustinB3403 said in Doubt on a script- Backup site & DB:

        Why use a delete function, wouldn't rsync automatically remove any files that are not in the source from the target?

        Yes, it will do that.

        A 1 Reply Last reply Reply Quote 0
        • D
          DustinB3403
          last edited by

          --delete
          			  This tells rsync to delete extraneous files from the receiving side (ones that arenât on the sending side), but only for the directories that are being synchronized.  You must have asked rsync to send the whole direcâ
          			  tory  (e.g.  "dir" or "dir/") without using a wildcard for the directoryâs contents (e.g. "dir/*") since the wildcard is expanded by the shell and rsync thus gets a request to transfer individual files, not the filesâ
          			  parent directory.  Files that are excluded from the transfer are also excluded from being deleted unless you use the --delete-excluded option or  mark  the  rules  as  only  matching  on  the  sending  side  (see  the
          			  include/exclude modifiers in the FILTER RULES section).
          
          1 Reply Last reply Reply Quote 0
          • D
            DustinB3403
            last edited by

            I wonder if --delete-excluded is the required approach with this, as it accounts for wildcards..

            According the manual --delete-excluded is for use cases where you're using the wildcard flag. So it would remove the folder and contents, rather than just the contents of a particular folder.

            A 1 Reply Last reply Reply Quote 0
            • A
              Ambarishrh @scottalanmiller
              last edited by

              @scottalanmiller said in Doubt on a script- Backup site & DB:

              @DustinB3403 said in Doubt on a script- Backup site & DB:

              Why use a delete function, wouldn't rsync automatically remove any files that are not in the source from the target?

              Yes, it will do that.

              If am not mistaken, plain rsync just syncs the difference to destination but does not deletes anything

              S 1 Reply Last reply Reply Quote 0
              • A
                Ambarishrh @DustinB3403
                last edited by

                @DustinB3403 said in Doubt on a script- Backup site & DB:

                I wonder if --delete-excluded is the required approach with this, as it accounts for wildcards..

                According the manual --delete-excluded is for use cases where you're using the wildcard flag. So it would remove the folder and contents, rather than just the contents of a particular folder.

                Fixed it! So the issue on my case was that i was transferring a file and adding --delete switch, whereas the --delete only works with a folder.

                --delete
                
                This tells rsync to delete extraneous files from the receiving side (ones that aren’t on the sending side), but only for the directories that are being synchronized. You must have asked rsync to send the whole directory (e.g. "dir" or "dir/") without using a wildcard for the directory’s contents (e.g. "dir/*") since the wildcard is expanded by the shell and rsync thus gets a request to transfer individual files, not the files’ parent directory. Files that are excluded from the transfer are also excluded from being deleted unless you use the --delete-excluded option or mark the rules as only matching on the sending side (see the include/exclude modifiers in the FILTER RULES section).
                

                So i updated my script and added the backup files to a dir and synced that, all works fine as expected.

                A 1 Reply Last reply Reply Quote 0
                • A
                  Ambarishrh @Ambarishrh
                  last edited by

                  Final script:

                  #Cleanup old backup files
                  rm -f /home/ACCOUNT_NAME/BACKUP_FOLDER/*
                  
                  #Insert date and a random key (key added to use it on public url to avoid guessing of public download link)
                  date=$(date +%Y-%m-%d)
                  key=$(head /dev/urandom | md5sum | cut -c1-10)
                  
                  #MySQLdump of the account to the backup folder
                  mysqldump -uDB_USER -pDB_PASSWORD --single-transaction DB_NAME 2>&1 | gzip > /home/ACCOUNT_NAME/BACKUP_FOLDER/backup-${date}-${key}_SITE_NAME.sql.gz
                  
                  #Compress the web directory and sql backup to a single backup file
                  tar czf /home/ACCOUNT_NAME/BACKUP_FOLDER/backup-${date}-${key}_SITE_NAME.tgz /home/ACCOUNT_NAME/public_html /home/ACCOUNT_NAME/BACKUP_FOLDER/backup-${date}-${key}_SITE_NAME.sql.gz 2> /dev/null
                  
                  #Rsync the final backup file to remote server, also cleanup existing old backup prior to the transfer by comparing source directory
                  rsync -a --delete /home/ACCOUNT_NAME/BACKUP_FOLDER/ REMOTE_USER@REMOTE_SERVER_URL:/home/ACCOUNT_NAME/public_html/SITE_NAME_BACKUP/
                  
                  #Email the backup link
                  echo "Latest backup is available at http://REMOTE_SERVER_URL/SITE_NAME_BACKUP/backup-${date}-${key}_SITE_NAME.tgz" | mail -s "Server backup available for download" USERNAME@DOMAIN.COM
                  1 Reply Last reply Reply Quote 2
                  • S
                    scottalanmiller @Ambarishrh
                    last edited by

                    @Ambarishrh said in Doubt on a script- Backup site & DB:

                    @scottalanmiller said in Doubt on a script- Backup site & DB:

                    @DustinB3403 said in Doubt on a script- Backup site & DB:

                    Why use a delete function, wouldn't rsync automatically remove any files that are not in the source from the target?

                    Yes, it will do that.

                    If am not mistaken, plain rsync just syncs the difference to destination but does not deletes anything

                    But you always select your flags, you never just use vanilla.

                    A 1 Reply Last reply Reply Quote 1
                    • A
                      Ambarishrh @scottalanmiller
                      last edited by Ambarishrh

                      @scottalanmiller said in Doubt on a script- Backup site & DB:

                      @Ambarishrh said in Doubt on a script- Backup site & DB:

                      @scottalanmiller said in Doubt on a script- Backup site & DB:

                      @DustinB3403 said in Doubt on a script- Backup site & DB:

                      Why use a delete function, wouldn't rsync automatically remove any files that are not in the source from the target?

                      Yes, it will do that.

                      If am not mistaken, plain rsync just syncs the difference to destination but does not deletes anything

                      But you always select your flags, you never just use vanilla.

                      But what was mentioned earlier

                      @DustinB3403 said in Doubt on a script- Backup site & DB:

                      Why use a delete function, wouldn't rsync automatically remove any files that are not in the source from the target?

                      From looking this up, other people have had similar issues, where using rsync -a --delete is effectively not rsyncing the files at all.

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        scottalanmiller @Ambarishrh
                        last edited by

                        @Ambarishrh oh I see.

                        1 Reply Last reply Reply Quote 0
                        • A
                          Ambarishrh
                          last edited by

                          Thanks @DustinB3403 for the help and pointers.

                          D 1 Reply Last reply Reply Quote 0
                          • D
                            DustinB3403 @Ambarishrh
                            last edited by

                            @Ambarishrh You're welcome, sorry I didn't have the exact answer for you.

                            A 1 Reply Last reply Reply Quote 0
                            • A
                              Ambarishrh @DustinB3403
                              last edited by

                              @DustinB3403 said in Doubt on a script- Backup site & DB:

                              @Ambarishrh You're welcome, sorry I didn't have the exact answer for you.

                              But that really helped me to find the right solution 🙂

                              1 Reply Last reply Reply Quote 0
                              • 1
                              • 2
                              • 1 / 2
                              • First post
                                Last post