Thread: Back up source daily with Backup Utility! [Any revision/Anything]

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 Back up source daily with Backup Utility! [Any revision/Anything] 
    Registered Member
    TnN_'s Avatar
    Join Date
    May 2014
    Posts
    252
    Thanks given
    324
    Thanks received
    115
    Rep Power
    507
    Here is a little tool I wrote to help you back up your src daily incase of anything going wrong throughout your project/server development! Should be pretty self explanitory. If you need help though just send me a PM I am always happy to help

    Place this where ever you like in your src.

    Code:
    package org.fb.util.backup;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    
    /**
     * File -> BackupUtility.java
     * <p>
     * Package -> org.fb.util.backup
     * <p>
     * Created for -> Nardah - BackupUtility
     *
     * @author Ethan Kyle Millard
     * @since 2/6/2017 @7:42 AM
     */
    public class BackupUtility {
    
        /**
         * The format of the date used in the zip of the folder.
         */
        private static final String DATE =  DateTimeFormatter.ofPattern("dd-MM-yyyy").format(LocalDate.now());
    
        /**
         * The directory of the source or folder to be zipped.
         */
        private static final String SOURCE_DIRECTORY_PATH = Paths.get("").toAbsolutePath().toString() + File.separator + "src";
    
        /**
         * The destination for the output in zip format.
         */
        private static final String DESTINATION_FOR_OUTPUT = Paths.get("").toAbsolutePath().toString() + File.separator + "data" + File.separator + "backup" + File.separator + "src-"+ DATE +".zip";
    
        /**
         * A logger to log the output.
         */
        private static final Logger logger = LoggerFactory.getLogger(BackupUtility.class);
    
        /**
         * Method used to pack all the files from {@code SOURCE_DIRECTORY_PATH} sourceDirPath to the {@code DESTINATION_FOR_OUTPUT}.
         */
        public static void packZip() {
            try {
    
                /*
                 * Checks if the File in {@code DESTINATION_FOR_OUTPUT} was already created, if so stop the method.
                 */
                if (new File(DESTINATION_FOR_OUTPUT).exists()) {
                    logger.info("The backup has already been created for today.");
                    return;
                }
    
                /*
                 * Creates a new file.
                 */
                Path p = Files.createFile(Paths.get(DESTINATION_FOR_OUTPUT));
    
                try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) {
    
                    /*
                     * Converts the {@link String} sourceDirPath to a path.
                     */
                    Path pp = Paths.get(SOURCE_DIRECTORY_PATH);
    
                    /*
                     * Returns a {@link Stream} that will be populated with all the file from given starting point.
                     */
                    Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> {
    
                        /*
                         * Constructs a new {@link Zip Entry}.
                         */
                        ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
    
                        try {
                            zs.putNextEntry(zipEntry);
                            zs.write(Files.readAllBytes(path));
                            zs.closeEntry();
                        } catch (Exception e) {
                            System.err.println(e);
                        }
    
                    });
    
                    logger.info("The backup has just been created for the date " + DATE + ".");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    }
    Call this method where you run the server, in the main method.

    Code:
    BackupUtility.packZip();
    Any feedback is appreciated Enjoy!
    Reply With Quote  
     


  2. #2  
    Registered Member dazas's Avatar
    Join Date
    Jun 2016
    Posts
    34
    Thanks given
    22
    Thanks received
    16
    Rep Power
    12
    Quote Originally Posted by Torv View Post
    Here is a little tool I wrote to help you back up your src daily incase of anything going wrong throughout your project/server development! Should be pretty self explanitory. If you need help though just send me a PM I am always happy to help

    Place this where ever you like in your src.

    Code:
    package org.fb.util.backup;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    
    /**
     * File -> BackupUtility.java
     * <p>
     * Package -> org.fb.util.backup
     * <p>
     * Created for -> Nardah - BackupUtility
     *
     * @author Ethan Kyle Millard
     * @since 2/6/2017 @7:42 AM
     */
    public class BackupUtility {
    
        /**
         * The format of the date used in the zip of the folder.
         */
        private static final String DATE =  DateTimeFormatter.ofPattern("dd-MM-yyyy").format(LocalDate.now());
    
        /**
         * The directory of the source or folder to be zipped.
         */
        private static final String SOURCE_DIRECTORY_PATH = Paths.get("").toAbsolutePath().toString() + File.separator + "src";
    
        /**
         * The destination for the output in zip format.
         */
        private static final String DESTINATION_FOR_OUTPUT = Paths.get("").toAbsolutePath().toString() + File.separator + "data" + File.separator + "backup" + File.separator + "src-"+ DATE +".zip";
    
        /**
         * A logger to log the output.
         */
        private static final Logger logger = LoggerFactory.getLogger(BackupUtility.class);
    
        /**
         * Method used to pack all the files from {@code SOURCE_DIRECTORY_PATH} sourceDirPath to the {@code DESTINATION_FOR_OUTPUT}.
         */
        public static void packZip() {
            try {
    
                /*
                 * Checks if the File in {@code DESTINATION_FOR_OUTPUT} was already created, if so stop the method.
                 */
                if (new File(DESTINATION_FOR_OUTPUT).exists()) {
                    logger.info("The backup has already been created for today.");
                    return;
                }
    
                /*
                 * Creates a new file.
                 */
                Path p = Files.createFile(Paths.get(DESTINATION_FOR_OUTPUT));
    
                try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) {
    
                    /*
                     * Converts the {@link String} sourceDirPath to a path.
                     */
                    Path pp = Paths.get(SOURCE_DIRECTORY_PATH);
    
                    /*
                     * Returns a {@link Stream} that will be populated with all the file from given starting point.
                     */
                    Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> {
    
                        /*
                         * Constructs a new {@link Zip Entry}.
                         */
                        ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
    
                        try {
                            zs.putNextEntry(zipEntry);
                            zs.write(Files.readAllBytes(path));
                            zs.closeEntry();
                        } catch (Exception e) {
                            System.err.println(e);
                        }
    
                    });
    
                    logger.info("The backup has just been created for the date " + DATE + ".");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    }
    Call this method where you run the server, in the main method.

    Code:
    BackupUtility.packZip();
    Any feedback is appreciated Enjoy!

    Good job mate!
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member
    TnN_'s Avatar
    Join Date
    May 2014
    Posts
    252
    Thanks given
    324
    Thanks received
    115
    Rep Power
    507
    Quote Originally Posted by dazas View Post
    Good job mate!
    Thanks man! I appreciate you
    Reply With Quote  
     

  5. #4  
    Registered Member
    Zivik's Avatar
    Join Date
    Oct 2007
    Age
    28
    Posts
    4,421
    Thanks given
    891
    Thanks received
    1,527
    Rep Power
    3285
    Good job man. Thanks for the share.
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa
    Planets's Avatar
    Join Date
    Aug 2014
    Age
    29
    Posts
    2,159
    Thanks given
    673
    Thanks received
    1,955
    Rep Power
    5000
    Good for those that dont use VCS. Nice release

    Reply With Quote  
     

  8. Thankful user:


  9. #6  
    Registered Member
    Vippy's Avatar
    Join Date
    Oct 2014
    Age
    25
    Posts
    2,572
    Thanks given
    984
    Thanks received
    1,933
    Rep Power
    5000
    Cheers fella nice job
    Reply With Quote  
     

  10. Thankful user:


  11. #7  
    Extreme Donator Back up source daily with Backup Utility! [Any revision/Anything] Market Banned



    Join Date
    Aug 2011
    Age
    28
    Posts
    3,589
    Thanks given
    1,402
    Thanks received
    1,620
    Rep Power
    5000
    Useful, Thanks Ethan

    Attached image

    Attached image
    Discord: Roy#2382

    Reply With Quote  
     

  12. Thankful user:


  13. #8  
    Registered Member

    Join Date
    Sep 2014
    Posts
    300
    Thanks given
    122
    Thanks received
    91
    Rep Power
    158
    Thanks for sharing. Well done.
    Reply With Quote  
     

  14. Thankful user:


  15. #9  
    Registered Member
    TnN_'s Avatar
    Join Date
    May 2014
    Posts
    252
    Thanks given
    324
    Thanks received
    115
    Rep Power
    507
    Thanks guy appreciate the positive feedback, been really hesitant to put some stuff I make out there due to the mean comments I usually see, again thanks guys
    Reply With Quote  
     

  16. #10  
    love

    scoob's Avatar
    Join Date
    Oct 2015
    Age
    25
    Posts
    1,642
    Thanks given
    367
    Thanks received
    640
    Rep Power
    1559
    Awesome release! I'm sure somebody will find it useful.
    Attached image
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 7
    Last Post: 03-17-2017, 02:01 PM
  2. Replies: 24
    Last Post: 12-03-2014, 11:19 PM
  3. req- ZDR open source client, with ip to put it
    By g m4ul3r in forum Requests
    Replies: 6
    Last Post: 03-22-2008, 07:01 PM
  4. paying 250k for an open source client with redstone
    By aaronhouston in forum Graphics
    Replies: 5
    Last Post: 12-09-2007, 12:24 AM
  5. Need Open Source Client With Redstones!!
    By aaronhouston in forum Requests
    Replies: 13
    Last Post: 11-24-2007, 06:09 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •