def remove_old() -> None: """Remove all old backups""" TealPrint.info("Removing old backups", color=attr("bold")) backup_path = Path(config.general.backup_location) for backup in backup_path.glob("*"): if backup.is_file() and date_helper.is_backup_old(backup): message = f"🔥 {backup}" TealPrint.info(message, indent=1) remove(backup)
def check_config_exists(self) -> None: if not self.path.exists(): TealPrint.info(f"Could not find any configuration file in {self.path}") user_input = input("Do you want to copy the example config and edit it (y/n)?") if user_input.lower() == "y": self.parser.copy_example_if_conf_not_exists(config.app_name) editor = "" if "EDITOR" in os.environ: editor = os.environ["EDITOR"] if editor == "" and platform.system() == "Windows": editor = "notepad.exe" elif editor == "": editor = "vim" run([editor, self.path]) else: exit(0)
def execute(self, channels: List[Channel]) -> None: for channel in channels: TealPrint.info(channel.name, color=LogColors.header, push_indent=True) videos = self.repo.get_latest_videos(channel) if len(videos) == 0: TealPrint.info( f"🦘 Skipping {channel.name}, no new matching videos to download", color=LogColors.skipped) for video in videos: TealPrint.verbose(f"🎞 {video.title}", color=LogColors.header, push_indent=True) # Skip downloaded videos if self.repo.has_downloaded(video): TealPrint.verbose( f"🟠Skipping {video.title}, already downloaded", color=LogColors.skipped) TealPrint.pop_indent() continue # Filter out if self._filter_video(channel, video): TealPrint.verbose(f"🔴 Video was filtered out", color=LogColors.filtered) TealPrint.pop_indent() continue TealPrint.verbose(f"🟢 Video passed all filters", color=LogColors.passed) TealPrint.verbose(f"🔽 Downloading...") download_path = self.repo.download(video) if download_path is None: TealPrint.warning(f"⚠Couldn't download {video.title}") TealPrint.pop_indent() continue TealPrint.verbose( f"🎞 Starting rendering, this may take a while...") out_path = self._get_out_filepath(channel, video) rendered = self.repo.render(video, download_path, out_path, channel.speed) if not rendered: TealPrint.warning(f"⚠Couldn't render {video.title}") TealPrint.pop_indent() continue self.repo.set_as_downloaded(channel, video) TealPrint.info( f"✔ Video {video.title} downloaded successfully ➡ {out_path}" ) TealPrint.pop_indent() TealPrint.pop_indent()
def run(self) -> None: """Add files to tar""" TealPrint.info(f"Backing up {self.name}", color=attr("bold")) # Full backup if self.part == BackupParts.full: TealPrint.info(f"Doing a full backup", indent=1) for path_glob in self.paths: TealPrint.verbose(f"{path_glob}", indent=2) for path in glob(path_glob): TealPrint.debug(f"{path}", indent=3) self.tar.add(path) # Diff backup else: TealPrint.info("Doing a diff backup", indent=1) for path_glob in self.paths: TealPrint.verbose(f"{path_glob}", indent=2) for path in glob(path_glob): self._find_diff_files(Path(path), 3)
def run(self) -> None: # Only run if a MySQL username and password has been supplied if not config.mysql.username and not config.mysql.password: TealPrint.info( "Skipping MySQL backup, no username and password supplied", color=fg("yellow"), ) return TealPrint.info("Backing up MySQL", color=attr("bold")) with tarfile.open(self.filepath, "w:gz") as tar: # Multiple database if len(config.mysql.databases) > 0: for database in config.mysql.databases: dump = self._get_database(database) self._add_to_tar_file(tar, database, dump) else: dump = self._get_database() self._add_to_tar_file(tar, "all-databases", dump) TealPrint.info("✔ MySQL backup complete!")