https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/boto/pyami/installers/ubuntu/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/boto/pyami/installers/ubuntu/__pycache__/ebs.cpython-310.pyc
o

ckF[�&�@sldZddlZddlmZddlmZddlZddlZddlm	Z	ddl
mZdZdZ
d	ZGd
d�de	�ZdS)a
Automated installer to attach, format and mount an EBS volume.
This installer assumes that you want the volume formatted as
an XFS file system.  To drive this installer, you need the
following section in the boto config passed to the new instance.
You also need to install dateutil by listing python-dateutil
in the list of packages to be installed in the Pyami seciont
of your boto config file.

If there is already a device mounted at the specified mount point,
the installer assumes that it is the ephemeral drive and unmounts
it, remounts it as /tmp and chmods it to 777.

Config file section::

    [EBS]
    volume_id = <the id of the EBS volume, should look like vol-xxxxxxxx>
    logical_volume_name = <the name of the logical volume that contaings
        a reference to the physical volume to be mounted. If this parameter
        is supplied, it overrides the volume_id setting.>
    device = <the linux device the EBS volume should be mounted on>
    mount_point = <directory to mount device, defaults to /ebs>

�N)�Volume)�EC2ResponseError)�	Installer)�Templateac#!/usr/bin/env python
# Backup EBS volume
import boto
from boto.pyami.scriptbase import ScriptBase
import traceback

class Backup(ScriptBase):

    def main(self):
        try:
            ec2 = boto.connect_ec2()
            self.run("/usr/sbin/xfs_freeze -f ${mount_point}", exit_on_error = True)
            snapshot = ec2.create_snapshot('${volume_id}')
            boto.log.info("Snapshot created: %s " %  snapshot)
        except Exception as e:
            self.notify(subject="${instance_id} Backup Failed", body=traceback.format_exc())
            boto.log.info("Snapshot created: ${volume_id}")
        except Exception as e:
            self.notify(subject="${instance_id} Backup Failed", body=traceback.format_exc())
        finally:
            self.run("/usr/sbin/xfs_freeze -u ${mount_point}")

if __name__ == "__main__":
    b = Backup()
    b.main()
z�#!/usr/bin/env python
import boto
from boto.manage.volume import Volume

# Cleans Backups of EBS volumes

for v in Volume.all():
    v.trim_snapshots(True)
zr#!/usr/bin/env python
import boto

# Cleans Backups of EBS volumes

ec2 = boto.connect_ec2()
ec2.trim_snapshots()
csdeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zddd
�Zdd�Z	dd�Z
dd�Zdd�Z�Z
S)�EBSInstallerz
    Set up the EBS stuff
    Ncshtt|��|�tj�dd�|_tj�ddd�|_tj�dd�|_tj�dd�|_	tj�ddd	�|_
dS)
N�Instancezinstance-id�EBS�devicez/dev/sdp�	volume_id�logical_volume_name�mount_pointz/ebs)�superr�__init__�boto�config�get�instance_idr	r
rr)�self�config_file��	__class__��B/usr/lib/python3/dist-packages/boto/pyami/installers/ubuntu/ebs.pyrhszEBSInstaller.__init__c
Csft��}|jrttj|jd��}|j|_|�|jg�d}|�	�dkr:tj
�d|j|j
f�t�d�|�	�dks#|�|jg�d}d}|r�z|�|j|j|j�d}Wn-ty�}z!|jdkrvtj
�d	|j|j|jf�t�d
�n|�WYd}~nd}~ww|sGtj
�d|j|j|jf�tj�|j�s�tj
�d|j�t�d
�tj�|j�r�dSdS)
N)�namer�	availablez1Volume %s not yet available. Current status = %s.�TF�IncorrectStatez]Attempt to attach the EBS volume %s to this instance (%s) returned %s. Trying again in a bit.�z.Attached volume %s to instance %s as device %sz*%s still does not exist, waiting 2 seconds)r�connect_ec2r�nextr�find�
_volume_idr
�get_all_volumes�update�log�info�id�status�time�sleep�get_only_instancesr�
attach_volumer	r�
error_code�errors�os�path�exists)r�ec2�logical_volume�volume�instance�attempt_attach�errr�attachps:
�
����
�zEBSInstaller.attachcCs<tj�d�|�d|j�}|dkr|�d|j�dSdS)Nz
make_fs...zfsck %srzmkfs -t xfs %s)rr$r%�runr	)r�has_fsrrr�make_fs�s
�zEBSInstaller.make_fscCsHtt�}|j|j|j|jd�}tdd�}|�|�|��|�	d�dS)N)r
rr�/usr/local/bin/ebs_backup�wz"chmod +x /usr/local/bin/ebs_backup)
r�BackupScriptTemplate�
substituter
rr�open�write�closer8)r�t�s�fprrr�create_backup_script�s�

z!EBSInstaller.create_backup_scriptFcCs:tdd�}|r
|�t�n|�t�|��|�d�dS)N�!/usr/local/bin/ebs_backup_cleanupr<z*chmod +x /usr/local/bin/ebs_backup_cleanup)r?r@�TagBasedBackupCleanupScript�BackupCleanupScriptrAr8)r�use_tag_based_cleanuprDrrr�create_backup_cleanup_script�s

z)EBSInstaller.create_backup_cleanup_scriptcCs�tj�d�tj�|j�stj�d�|�d|j�n>tj�d�|�d�|jj	�
d�}|D])}|�
�}|rY|d|jkrY|d|jkrY|�d	|j�|�d
|d�nq0|�d�|�d|j|jf�|�d
|j�dS)N�handle_mount_pointzmaking directoryzmkdir %szdirectory exists alreadyzmount -l�
rrz	umount %sz
mount %s /tmpzchmod 777 /tmpzmount %s %sz
xfs_growfs %s)rr$r%r.r/�isdirrr8�last_command�output�splitr	)r�lines�linerBrrrrK�s$
�
zEBSInstaller.handle_mount_pointcCs,tdd�}|�d|j|jf�|��dS)Nz
/etc/fstab�az%s	%s	xfs	defaults 0 0
)r?r@r	rrA)r�frrr�update_fstab�s
zEBSInstaller.update_fstabcCs�|��|�d�|��|��|��tj�ddd�}tj�ddd�}|jdd||d	�tj�dd
�}tj�dd�}|durY|durYtj�	dd�}|�
|�|jd
d||d	�|��dS)Nz#apt-get -y install xfsprogs xfsdumpr�backup_cron_minute�0�backup_cron_hourz4,16�
ebs_backupr;)�minute�hour�backup_cleanup_cron_minute�backup_cleanup_cron_hour�use_tag_based_snapshot_cleanup�ebs_backup_cleanuprF)r7r8r:rKrErrr�add_cron�
has_optionrJrU)rrZr[rIrrr�install�s

zEBSInstaller.installcCs0tj�|j�s
|��dStj�d|j�dS)Nz5Device %s is already attached, skipping EBS Installer)r.r/r0r	rbrr$r%)rrrr�main�szEBSInstaller.main)N)F)�__name__�
__module__�__qualname__�__doc__rr7r:rErJrKrUrbrc�
__classcell__rrrrrcs!
		$r)rgr�boto.manage.volumer�boto.exceptionrr.r(�&boto.pyami.installers.ubuntu.installerr�stringrr=rHrGrrrrr�<module>s
	

https://t.me/RX1948 - 2025