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

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17
  1. #11  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    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 {
    
         private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    
         public static void main(String...args){
             logger.info("Starting up backup utility executor."); 
    	 scheduler .scheduleAtFixedRate(()->{ packZip(); }, 12, 12, TimeUnit.HOURS);
        }
    
        /**
         * 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();
            }
        }
    
    }
    Just a small addition, maybe saved a few seconds to someone

    Nice
    Reply With Quote  
     

  2. Thankful users:


  3. #12  
    Registered Member
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    26
    Posts
    5,103
    Thanks given
    1,818
    Thanks received
    1,767
    Rep Power
    2438
    good job, i do something similar to this to backup player files on a daily basis

    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Spoiler for skrrrrr:

    Attached image
    Reply With Quote  
     

  4. Thankful user:


  5. #13  
    Donator


    Join Date
    Jan 2014
    Posts
    1,652
    Thanks given
    428
    Thanks received
    501
    Rep Power
    221
    Good stuff bro
    Reply With Quote  
     

  6. #14  
    Respected Member


    George's Avatar
    Join Date
    Mar 2009
    Posts
    7,099
    Thanks given
    2,226
    Thanks received
    3,146
    Rep Power
    5000
    Git or bitbucket O_o?
    Attached image

    Spoiler for Spoilers!:
    Attached image
    Attached image
    Attached image
    Attached image
    Reply With Quote  
     

  7. Thankful users:


  8. #15  
    Respected Member


    Polar's Avatar
    Join Date
    Sep 2015
    Age
    28
    Posts
    420
    Thanks given
    0
    Thanks received
    418
    Rep Power
    3098
    As others have said this isn't really needed if you use some kind of version control(git), but could be useful if you store characters in a file and want to back those up daily.
    Reply With Quote  
     

  9. #16  
    Registered Member
    Join Date
    Aug 2017
    Posts
    1
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Clearly some people haven't heard of git, lol.
    Reply With Quote  
     

  10. #17  
    Registered Member

    Join Date
    May 2013
    Age
    27
    Posts
    414
    Thanks given
    215
    Thanks received
    200
    Rep Power
    137
    Quote Originally Posted by Zenadix View Post
    Clearly some people haven't heard of git, lol.
    Clearly you didnt read the forum rules about grave digging, lol.
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

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
  •