diff --git a/README.md b/README.md index 2d7369e..db10f7b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Archivist is automatically launched periodicaly to update your backups and send -**Shipped version:** 1.3.4~ynh1 +**Shipped version:** 1.3.4~ynh2 ## Disclaimers / important information ## Configuration diff --git a/README_fr.md b/README_fr.md index 3e70e73..a5b0607 100644 --- a/README_fr.md +++ b/README_fr.md @@ -23,7 +23,7 @@ Vos sauvegardes peuvent être envoyées à de nombreux autres endroits, locaux o Archivist est automatiquement lancé périodiquement pour mettre à jour vos sauvegardes et envoyer les modifications aux autres emplacements. -**Version incluse :** 1.3.4~ynh1 +**Version incluse :** 1.3.4~ynh2 ## Avertissements / informations importantes ## Configuration diff --git a/check_process b/check_process index 6d66784..9021b41 100644 --- a/check_process +++ b/check_process @@ -5,6 +5,7 @@ core_backup=true apps_backup=true frequency="Weekly" + max_size="500" ; Checks pkg_linter=1 setup_sub_dir=0 @@ -25,4 +26,4 @@ Notification=change ;;; Upgrade options ; #commit=2b2793737d5e1374659cbb74838d10162a2147e6 #name=03 Nov 2017 2b2793737d5e1374659cbb74838d10162a2147e6 - manifest_arg=encrypt=1&encryption_pwd="password"&core_backup=1&apps_backup=1&frequency="Weekly"& + manifest_arg=encrypt=true&encryption_pwd="password"&core_backup=true&apps_backup=true&frequency="Weekly"&max_size=500& diff --git a/conf/Backup_list.conf.default b/conf/Backup_list.conf.default new file mode 100644 index 0000000..f8bb8eb --- /dev/null +++ b/conf/Backup_list.conf.default @@ -0,0 +1,139 @@ +## OPTIONS + +# Backup directory. +backup_dir="__BACKUP_DIR__" + +# Encrypted backup directory. +# Usually just next to the backup directory +enc_backup_dir="__ENC_BACKUP_DIR__" + +# Encryption +# true/false +encrypt=__ENCRYPT__ +# Password for encryption +# This file should be set at chmod 400 +cryptpass="__PASSKEY__" + +# Compression algorithm to use +# gzip +# Standard compression algorithm. +# Fast and light on ressources. +# lzop +# Very fast algorithm. +# Low efficency +# zstd +# Zstandard algorithm +# Similar to gzip but faster +# bzip2 +# Very slow but very effective. +# Light on ressources. +# lzma +# Faster than bzip2 and even more effective. +# But demanding in resources. +# lzip +# Similar to lzma. +# xz +# Similar to lzma but more recent. +# +# none +# No compression +# Concatenation in a tar file only +# symlink +# No compression +# Symbolic link to the YunoHost tar file from /home/yunohost.backup/archives +# The symbolic link is used only for the local $backup_dir of archivist. +# Real tar files are send to recipients. +# +# This mode allow archivist to not duplicate locally the backup if not compressed. +# WARNING: Does not work with encryption ! +# +# Default: gzip +ynh_compression_mode=__COMPRESS_YNH__ +files_compression_mode=__COMPRESS_FILES__ + +# -------------------------------------------------------------------------------------- +## YUNOHOST BACKUPS + +# YunoHost backups +# Specific backup made by 'yunohost backup' command +# ynh_core_backup=__CORE_BACKUP__: Make a backup of the core of YunoHost, without any apps. +ynh_core_backup=true +ynh_core_pre_backup= +ynh_core_post_backup= + +# ynh_app_backup=APP: Make a backup of an app. +# You can add as many lines as you want to save multiple apps. +# List all apps with sudo yunohost app list --installed | grep "id: " +# ynh_app_backup=wordpress +# If you don't want an app with a lot of data to backup those big files, please add 'do_not_backup_data' after the app name. +# ynh_app_backup=transmission do_not_backup_data +ynh_app_pre_backup= +ynh_app_post_backup= +ynh_app_backup= + +# -------------------------------------------------------------------------------------- +## FILES BACKUPS + +# Max size for each backup in Mb. +# Be carreful, it's only a soft limit, that means the script will try to limit each backup. +# Because, it will never made more than one backup for a single directory (Even if it's a real big directory without subdirectories). And the same if there's files next to subdirectories, only one backup will be made for all this files. +max_size=500 + +# Backup of files and directories +# Add as many lines as you want for each directory or file you want to be backuped. +# Exclude a directory, a file, or multiples files with a regex with the exclude_backup instruction. +# file_to_backup="/directory/to backup" +# file_to_backup=/file/to backup +# exclude_backup="/directory/to exclude" +# exclude_backup=/file/to exclude +# exclude_backup="/exclude/all/tarball/in_this_directory/.tar.gz$" +files_pre_backup= +files_post_backup= +file_to_backup= +exclude_backup= + +# -------------------------------------------------------------------------------------- +## BACKUPS RECIPIENTS + +# All options following a recipient name will be enabled for this recipient only. +# > recipient name=Name of this recipient. +# type=Choose between one of the scripts in the "senders" directory. +# destination directory=Directory where to put the backup in the other side. +# encrypt=Override main option for encryption. (true/false) (Optionnal option) +# specific option for type=See the chosen script to know what's the options. +# exclude backup=Exclude a backup file or a directory from the backup. This option can be duplicated. (Optionnal option) +# include backup=Choose the only file or directory which be send. This option can be duplicated. (Optionnal option) + +# > recipient name=local example +# type=local +# destination directory=/my/local/backup +# encrypt=false +# pre_backup= +# post_backup= +# exclude backup=/exclude/dir +# include backup= + +# > recipient name=rsync ssh example +# type=rsync_ssh +# destination directory=backup +# encrypt=false +# ssh_host=domain.tld +# ssh_user=user +# ssh_port=22 +# ssh_key=/home/user/.ssh/id_rsa +# ssh_pwd= +# ssh_options= +# pre_backup= +# post_backup= +# exclude backup=/exclude/dir +# include backup= + +# > recipient name=b2 example +# type=b2 +# destination directory=backup +# encrypt=false +# b2_bucket=my-bucket +# pre_backup= +# post_backup= +# exclude backup=/exclude/dir +# include backup= diff --git a/conf/sudoer b/conf/sudoer new file mode 100644 index 0000000..a537c69 --- /dev/null +++ b/conf/sudoer @@ -0,0 +1 @@ +__APP__ ALL=(root) NOPASSWD: /usr/bin/yunohost backup create *, /usr/bin/yunohost backup restore *, /usr/bin/yunohost backup delete *, /usr/bin/yunohost app list *, /usr/bin/yunohost app remove *, /bin/ls diff --git a/config_panel.toml.bak b/config_panel.toml.bak new file mode 100644 index 0000000..6debd3d --- /dev/null +++ b/config_panel.toml.bak @@ -0,0 +1,85 @@ +version = "1.0" + +[main] +name = "Archivist configuration" + + [main.encryption] + name = "Encryption" + + [main.encryption.encrypt] + ask = "Do you want to encrypt your backups ?" + type = "boolean" + default = true + bind = "encrypt:__FINAL_PATH__/Backup_list.conf" + + [main.encryption.encryption_pwd] + ask = "Set the password for encryption" + type = "password" + optional = true + help = "A password is needed if encryption is activated." + bind = "__FINAL_PATH__/passkey" + + [main.compression] + name = "Compression algorithm" + + [main.compression.compress_ynh] + ask = "Choose the compression algorithm for YunoHost backups" + type = "select" + choices = ["gzip", "lzop", "zstd", "bzip2", "lzma", "lzip", "xz", "No compression"] + default = "gzip" + bind = "ynh_compression_mode:__FINAL_PATH__/Backup_list.conf" + + [main.compression.compress_files] + ask = "Choose the compression algorithm for files and directories backups" + type = "select" + choices = ["gzip", "lzop", "zstd", "bzip2", "lzma", "lzip", "xz", "No compression"] + default = "gzip" + bind = "files_compression_mode:__FINAL_PATH__/Backup_list.conf" + + [main.backup_types] + name = "Backup" + + [main.backup_types.core_backup] + ask = "Would you like to backup your YunoHost core ?" + type = "boolean" + default = true + bind = "ynh_core_backup:__FINAL_PATH__/Backup_list.conf" + + [main.backup_types.apps_backup] + ask = "Would you like to backup your apps ?" + type = "boolean" + default = true + help = "WARNING: Changing this value will either remove backup for all apps or add all current apps to the backup." + + [main.backup_options] + name = "Backup options" + + [main.backup_options.frequency] + ask = "Choose the frequency of your backups ?" + type = "select" + choices = ["Daily", "Each 3 days", "Weekly", "Biweekly", "Monthly"] + default = "Weekly" + + [main.backup_options.max_size] + ask = "Max size for each backup in Mb" + type = "number" + default = 500 + help = "Specify the max size of each backup for the following option file_to_backup.
This option is a soft limit, that means the script will try to limit each backup to this max size if it can.
But there's 2 limitations, for a single directory, it can't makes more than one backup file, even if the files in this directory exceed this maximum size.
And, if there's some files in a directory, next to subdirectories, it'll make only one backup for this files.
So this limit will be applied to split the backup by its subdirectories to avoid to have only one big backup." + + [main.overwrite_files] + name = "Overwriting config files" + + [main.overwrite_files.overwrite_cron] + ask = "Overwrite the cron file during the upgrade ?" + type = "boolean" + default = true + help = "If the file is overwritten, a backup will be created." + + [main.global_config] + name = "Global configuration" + + [main.global_config.email_type] + ask = "Send HTML email to admin ?" + type = "boolean" + default = true + help = "Allow app scripts to send HTML mails instead of plain text." diff --git a/manifest.json b/manifest.json index cc9fb77..37f8501 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Automatic backups", "fr": "Sauvegardes automatiques" }, - "version": "1.3.4~ynh1", + "version": "1.3.4~ynh2", "url": "https://github.com/maniackcrudelis/archivist", "upstream": { "license": "GPL-3.0", @@ -77,6 +77,15 @@ }, "choices" : ["Daily", "Each 3 days", "Weekly", "Biweekly", "Monthly"], "default" : "Weekly" + }, + { + "name": "max_size", + "type": "select", + "ask": { + "en": "Specify the max size of each files backup (soft limit) in Mb. This will try to split the backup by its subdirectories to avoid to have only one big backup." + }, + "choices" : ["50", "100", "500", "1000", "5000"], + "default" : "500" } ] } diff --git a/scripts/config b/scripts/config.bak similarity index 99% rename from scripts/config rename to scripts/config.bak index 046aa67..70ddc89 100644 --- a/scripts/config +++ b/scripts/config.bak @@ -13,8 +13,6 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -app=$YNH_APP_INSTANCE_NAME - final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= @@ -124,7 +122,7 @@ apply_config() { #================================================= # Change the password if needed - if [ "$encrypt" ] + if [ "$encrypt" = true ] then ynh_print_OFF test -n "$encrypt_password" || ynh_die --message="The password for encryption can't be empty if you choose to enable encryption." diff --git a/scripts/install b/scripts/install index d1bae3d..c45eeef 100755 --- a/scripts/install +++ b/scripts/install @@ -25,6 +25,9 @@ encryption_pwd=$YNH_APP_ARG_ENCRYPTION_PWD core_backup=$YNH_APP_ARG_CORE_BACKUP apps_backup=$YNH_APP_ARG_APPS_BACKUP frequency="$YNH_APP_ARG_FREQUENCY" +max_size="$YNH_APP_ARG_MAX_SIZE" +compress_ynh="gzip" # by default +compress_files="gzip" # by default app=$YNH_APP_INSTANCE_NAME @@ -36,7 +39,7 @@ ynh_script_progression --message="Validating installation parameters..." final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -if [ $encrypt -eq 1 ]; then +if [ "$encrypt" = true ]; then test -n "$encryption_pwd" || ynh_die --message="encryption_pwd can't be empty if you choose to enable encryption." fi @@ -46,13 +49,18 @@ fi ynh_script_progression --message="Storing installation settings..." --weight=3 ynh_app_setting_set --app=$app --key=frequency --value="$frequency" +ynh_app_setting_set --app=$app --key=max_size --value=$max_size ynh_app_setting_set --app=$app --key=encrypt --value="$encrypt" + ynh_app_setting_set --app=$app --key=core_backup --value="$core_backup" ynh_app_setting_set --app=$app --key=apps_backup --value="$apps_backup" ynh_app_setting_set --app=$app --key=overwrite_cron --value=1 ynh_app_setting_set --app=$app --key=admin_mail_html --value=1 +ynh_app_setting_set --app=$app --key=compress_ynh --value=$compress_ynh +ynh_app_setting_set --app=$app --key=compress_files --value=$compress_files + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -71,6 +79,8 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 +ynh_system_user_create --username=$app --groups="admins" + ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" @@ -91,15 +101,9 @@ mkdir -p "$backup_dir" ynh_script_progression --message="Configuring Archivist..." --weight=2 config_file="$final_path/Backup_list.conf" -cp "$final_path/Backup_list.conf.default" "$config_file" -ynh_replace_string --match_string="^backup_dir=.*" --replace_string="backup_dir=$backup_dir" --target_file="$config_file" -ynh_replace_string --match_string="^enc_backup_dir=.*" --replace_string="enc_backup_dir=$enc_backup_dir" --target_file="$config_file" - -if [ $encrypt -eq 1 ] +if [ "$encrypt" = true ] then - encrypt=true - passkey="$final_path/passkey" echo "$encryption_pwd" > "$passkey" chmod 400 "$passkey" @@ -107,18 +111,10 @@ else encrypt=false passkey=na fi -ynh_replace_string --match_string="^encrypt=.*" --replace_string="encrypt=$encrypt" --target_file="$config_file" -ynh_replace_string --match_string="^cryptpass=.*" --replace_string="cryptpass=$passkey" --target_file="$config_file" -if [ $core_backup -eq 1 ] -then - core_backup=true -else - core_backup=false -fi -ynh_replace_string --match_string="^ynh_core_backup=.*" --replace_string="ynh_core_backup=$core_backup" --target_file="$config_file" +ynh_add_config --template="Backup_list.conf.default" --destination="$config_file" -if [ $apps_backup -eq 1 ] +if [ "$apps_backup" = true ] then # Add all current applications to the backup while read backup_app @@ -135,9 +131,6 @@ ynh_store_file_checksum --file="$config_file" #================================================= ynh_script_progression --message="Configuring the cron file..." -cp ../conf/cron /etc/cron.d/$app -ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app -ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app if [ "$frequency" = "Daily" ]; then cron_freq="0 2 * * *" run_freq="every day" @@ -154,7 +147,8 @@ else # Monthly cron_freq="0 2 1 * *" run_freq="once a month on the first sunday" fi -ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app + +ynh_add_config --template="cron" --destination="/etc/cron.d/$app" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="/etc/cron.d/$app" @@ -164,7 +158,7 @@ ynh_store_file_checksum --file="/etc/cron.d/$app" #================================================= # Set permissions to app files -chown -R root: $final_path +chown -R $app: $final_path #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 55db47e..173bed1 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -118,10 +118,7 @@ if [ $overwrite_cron -eq 1 ] then # Verify the checksum and backup the file if it's different ynh_backup_if_checksum_is_different --file="/etc/cron.d/$app" - - cp ../conf/cron /etc/cron.d/$app - ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file=/etc/cron.d/$app - ynh_replace_string --match_string="__APP__" --replace_string=$app --target_file=/etc/cron.d/$app + if [ "$frequency" = "Daily" ]; then cron_freq="0 2 * * *" run_freq="every day" @@ -138,7 +135,8 @@ then cron_freq="0 2 1 * *" run_freq="once a month on the first sunday" fi - ynh_replace_string --match_string="__FREQUENCY__" --replace_string="$cron_freq" --target_file=/etc/cron.d/$app + + ynh_add_config --template="cron" --destination="/etc/cron.d/$app" # Recalculate and store the config file checksum into the app settings ynh_store_file_checksum --file="/etc/cron.d/$app" @@ -149,7 +147,7 @@ fi #================================================= # Set permissions on app files -chown -R root: $final_path +chown -R $app: $final_path #================================================= # GENERIC FINALIZATION